Skip to content

Commit 4b4f3d2

Browse files
pan3793zhaohehuhu
authored andcommitted
[KYUUBI apache#6016] Conditional call GetInfo CLI_ODBC_KEYWORDS to restore compatible with lower version Kyuubi and HS2
# 🔍 Description ## Issue References 🔗 Currently, the Kyuubi Beeline is not compatible with HS2 2.3 and lower versions of Kyuubi, because the server can not recognize `TGetInfoType.CLI_ODBC_KEYWORDS` and then corrupts the socket. ## Describe Your Solution 🔧 Conditional call GetInfo CLI_ODBC_KEYWORDS, when protocol version lower than TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11, just throw an SQLFeatureNotSupportedException ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 Use beeline to connect a HS2 2.3 #### Behavior Without This Pull Request ⚰️ ``` roothadoop-master1:/opt/kyuubi-dev# bin/beeline -u 'jdbc:hive2://localhost:10000/default' Warn: Not find kyuubi environment file /etc/kyuubi/conf/kyuubi-env.sh, using default ones... Connecting to jdbc:hive2://localhost:10000/default Connected to: Apache Hive (version 2.3.9) Driver: Kyuubi Project Hive JDBC Client (version 1.8.0) Beeline version 1.8.0 by Apache Kyuubi 0: jdbc:hive2://localhost:10000/default> select 1; Unexpected end of file when reading from HS2 server. The root cause might be too many concurrent connections. Please ask the administrator to check the number of active connections, and adjust hive.server2.thrift.max.worker.threads if applicable. Error: org.apache.thrift.transport.TTransportException (state=08S01,code=0) ``` And the HS2 server-side error message is ``` 24/01/25 03:50:53 [37217e6b-e8a9-4069-9973-10471df52e6d HiveServer2-Handler-Pool: Thread-37]: INFO conf.HiveConf: Using the default value passed in for log id: 37217e6b-e8a9-4069-9973-10471df52e6d 24/01/25 03:50:53 [HiveServer2-Handler-Pool: Thread-37]: ERROR server.TThreadPoolServer: Thrift error occurred during processing of message. org.apache.thrift.protocol.TProtocolException: Missing version in readMessageBegin, old client? at org.apache.thrift.protocol.TBinaryProtocol.readMessageBegin(TBinaryProtocol.java:228) ~[hive-exec-2.3.9.jar:2.3.9] at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:27) ~[hive-exec-2.3.9.jar:2.3.9] at org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56) ~[hive-service-2.3.9.jar:2.3.9] at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286) ~[hive-exec-2.3.9.jar:2.3.9] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_392] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_392] at java.lang.Thread.run(Thread.java:750) [?:1.8.0_392] 24/01/25 03:50:53 [HiveServer2-Handler-Pool: Thread-37]: INFO thrift.ThriftCLIService: Session disconnected without closing properly. 24/01/25 03:50:53 [HiveServer2-Handler-Pool: Thread-37]: INFO thrift.ThriftCLIService: Closing the session: SessionHandle [37217e6b-e8a9-4069-9973-10471df52e6d] ``` #### Behavior With This Pull Request 🎉 ``` roothadoop-master1:/opt/kyuubi-dev# bin/beeline -u 'jdbc:hive2://localhost:10000/default' Warn: Not find kyuubi environment file /etc/kyuubi/conf/kyuubi-env.sh, using default ones... Connecting to jdbc:hive2://localhost:10000/default Connected to: Apache Hive (version 2.3.9) Driver: Kyuubi Project Hive JDBC Client (version 1.9.0-SNAPSHOT) Beeline version 1.9.0-SNAPSHOT by Apache Kyuubi 0: jdbc:hive2://localhost:10000/default> select 1; +------+ | _c0 | +------+ | 1 | +------+ 1 row selected (2.403 seconds) 0: jdbc:hive2://localhost:10000/default> ``` --- # Checklist 📝 - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes apache#6016 from pan3793/jdbc-comp. Closes apache#6016 413c7a4 [Cheng Pan] Conditional call GetInfo CLI_ODBC_KEYWORDS to restore compatible with lower version Kyuubi and HS2 Authored-by: Cheng Pan <[email protected]> Signed-off-by: Cheng Pan <[email protected]>
1 parent 68d1084 commit 4b4f3d2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public DatabaseMetaData getMetaData() throws SQLException {
11321132
if (isClosed) {
11331133
throw new KyuubiSQLException("Connection is closed");
11341134
}
1135-
return new KyuubiDatabaseMetaData(this, client, sessHandle);
1135+
return new KyuubiDatabaseMetaData(this, protocol, client, sessHandle);
11361136
}
11371137

11381138
@Override
@@ -1179,7 +1179,7 @@ public boolean isValid(int timeout) throws SQLException {
11791179
}
11801180
boolean rc = false;
11811181
try {
1182-
new KyuubiDatabaseMetaData(this, client, sessHandle).getDatabaseProductName();
1182+
new KyuubiDatabaseMetaData(this, protocol, client, sessHandle).getDatabaseProductName();
11831183
rc = true;
11841184
} catch (SQLException ignore) {
11851185
}

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919

2020
import static org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId.*;
2121

22-
import java.sql.Connection;
23-
import java.sql.DatabaseMetaData;
24-
import java.sql.ResultSet;
25-
import java.sql.SQLException;
22+
import java.sql.*;
2623
import java.util.ArrayList;
2724
import java.util.Arrays;
2825
import java.util.Comparator;
@@ -37,6 +34,7 @@
3734
public class KyuubiDatabaseMetaData implements SQLDatabaseMetaData {
3835

3936
private final KyuubiConnection connection;
37+
private final TProtocolVersion protocol;
4038
private final TCLIService.Iface client;
4139
private final TSessionHandle sessHandle;
4240
private static final String CATALOG_SEPARATOR = ".";
@@ -50,8 +48,12 @@ public class KyuubiDatabaseMetaData implements SQLDatabaseMetaData {
5048
private String dbVersion = null;
5149

5250
public KyuubiDatabaseMetaData(
53-
KyuubiConnection connection, TCLIService.Iface client, TSessionHandle sessHandle) {
51+
KyuubiConnection connection,
52+
TProtocolVersion protocol,
53+
TCLIService.Iface client,
54+
TSessionHandle sessHandle) {
5455
this.connection = connection;
56+
this.protocol = protocol;
5557
this.client = client;
5658
this.sessHandle = sessHandle;
5759
}
@@ -568,6 +570,12 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
568570

569571
@Override
570572
public String getSQLKeywords() throws SQLException {
573+
if (protocol.compareTo(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11) < 0) {
574+
throw new SQLFeatureNotSupportedException(
575+
String.format(
576+
"Feature is not supported, protocol version is %s, requires %s or higher",
577+
protocol, TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V11));
578+
}
571579
// Note: the definitions of what ODBC and JDBC keywords exclude are different in different
572580
// places. For now, just return the ODBC version here; that excludes Hive keywords
573581
// that are also ODBC reserved keywords. We could also exclude SQL:2003.

0 commit comments

Comments
 (0)