You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2022/09/23 03:45:25 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #3451] Implement GetInfo for JDBC engine

This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e07d27e9 [KYUUBI #3451] Implement GetInfo for JDBC engine
0e07d27e9 is described below

commit 0e07d27e9f91c94e4703d6649dd2037cb838b2d4
Author: yikf <yi...@gmail.com>
AuthorDate: Fri Sep 23 11:45:13 2022 +0800

    [KYUUBI #3451] Implement GetInfo for JDBC engine
    
    ### _Why are the changes needed?_
    
    Fix https://github.com/apache/incubator-kyuubi/issues/3451
    
    This pr aims to implement GetInfo for JDBC engine.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
    
    Closes #3538 from Yikf/jdbc-getinfo.
    
    Closes #3451
    
    cd6e1e75 [yikf] Support getInfo in jdbc
    
    Authored-by: yikf <yi...@gmail.com>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 .../engine/jdbc/session/JdbcSessionImpl.scala      | 26 +++++++++++++--
 .../jdbc/doris/OperationWithEngineSuite.scala      | 38 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
index 92ed7144c..63fb2dd07 100644
--- a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
+++ b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
@@ -16,12 +16,13 @@
  */
 package org.apache.kyuubi.engine.jdbc.session
 
-import java.sql.Connection
+import java.sql.{Connection, DatabaseMetaData}
 
 import scala.util.{Failure, Success, Try}
 
-import org.apache.hive.service.rpc.thrift.TProtocolVersion
+import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion}
 
+import org.apache.kyuubi.KyuubiSQLException
 import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider
 import org.apache.kyuubi.session.{AbstractSession, SessionManager}
 
@@ -36,17 +37,38 @@ class JdbcSessionImpl(
 
   private[jdbc] var sessionConnection: Connection = _
 
+  private var databaseMetaData: DatabaseMetaData = _
+
   private val kyuubiConf = sessionManager.getConf
 
   override def open(): Unit = {
     info(s"Starting to open jdbc session.")
     if (sessionConnection == null) {
       sessionConnection = ConnectionProvider.create(kyuubiConf)
+      databaseMetaData = sessionConnection.getMetaData
     }
     super.open()
     info(s"The jdbc session is started.")
   }
 
+  override def getInfo(infoType: TGetInfoType): TGetInfoValue = withAcquireRelease() {
+    assert(databaseMetaData != null, "JDBC session has not been initialized")
+    infoType match {
+      case TGetInfoType.CLI_SERVER_NAME | TGetInfoType.CLI_DBMS_NAME =>
+        TGetInfoValue.stringValue(databaseMetaData.getDatabaseProductName)
+      case TGetInfoType.CLI_DBMS_VER =>
+        TGetInfoValue.stringValue(databaseMetaData.getDatabaseProductVersion)
+      case TGetInfoType.CLI_ODBC_KEYWORDS => TGetInfoValue.stringValue("Unimplemented")
+      case TGetInfoType.CLI_MAX_COLUMN_NAME_LEN =>
+        TGetInfoValue.lenValue(databaseMetaData.getMaxColumnNameLength)
+      case TGetInfoType.CLI_MAX_SCHEMA_NAME_LEN =>
+        TGetInfoValue.lenValue(databaseMetaData.getMaxSchemaNameLength)
+      case TGetInfoType.CLI_MAX_TABLE_NAME_LEN =>
+        TGetInfoValue.lenValue(databaseMetaData.getMaxTableNameLength)
+      case _ => throw KyuubiSQLException(s"Unrecognized GetInfoType value: $infoType")
+    }
+  }
+
   override def close(): Unit = {
     Try {
       if (sessionConnection != null) {
diff --git a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/OperationWithEngineSuite.scala b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/OperationWithEngineSuite.scala
index 1d1414798..a1814e702 100644
--- a/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/OperationWithEngineSuite.scala
+++ b/externals/kyuubi-jdbc-engine/src/test/scala/org/apache/kyuubi/engine/jdbc/doris/OperationWithEngineSuite.scala
@@ -16,9 +16,47 @@
  */
 package org.apache.kyuubi.engine.jdbc.doris
 
+import org.apache.hive.service.rpc.thrift.{TGetInfoReq, TGetInfoType}
+
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider
 import org.apache.kyuubi.operation.HiveJDBCTestHelper
 
 class OperationWithEngineSuite extends DorisOperationSuite with HiveJDBCTestHelper {
 
   override protected def jdbcUrl: String = jdbcConnectionUrl
+
+  test("Test for Jdbc engine getInfo") {
+    val metaData = ConnectionProvider.create(kyuubiConf).getMetaData
+
+    withSessionConf(Map(KyuubiConf.SERVER_INFO_PROVIDER.key -> "ENGINE"))()() {
+      withSessionHandle { (client, handle) =>
+        val req = new TGetInfoReq()
+        req.setSessionHandle(handle)
+        req.setInfoType(TGetInfoType.CLI_DBMS_NAME)
+        assert(client.GetInfo(req).getInfoValue.getStringValue == metaData.getDatabaseProductName)
+
+        val req2 = new TGetInfoReq()
+        req2.setSessionHandle(handle)
+        req2.setInfoType(TGetInfoType.CLI_DBMS_VER)
+        assert(
+          client.GetInfo(req2).getInfoValue.getStringValue == metaData.getDatabaseProductVersion)
+
+        val req3 = new TGetInfoReq()
+        req3.setSessionHandle(handle)
+        req3.setInfoType(TGetInfoType.CLI_MAX_COLUMN_NAME_LEN)
+        assert(client.GetInfo(req3).getInfoValue.getLenValue == metaData.getMaxColumnNameLength)
+
+        val req4 = new TGetInfoReq()
+        req4.setSessionHandle(handle)
+        req4.setInfoType(TGetInfoType.CLI_MAX_SCHEMA_NAME_LEN)
+        assert(client.GetInfo(req4).getInfoValue.getLenValue == metaData.getMaxSchemaNameLength)
+
+        val req5 = new TGetInfoReq()
+        req5.setSessionHandle(handle)
+        req5.setInfoType(TGetInfoType.CLI_MAX_TABLE_NAME_LEN)
+        assert(client.GetInfo(req5).getInfoValue.getLenValue == metaData.getMaxTableNameLength)
+      }
+    }
+  }
 }