diff --git a/externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/session/HiveSessionImpl.scala b/externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/session/HiveSessionImpl.scala index 6d1185c70..91db1cb8d 100644 --- a/externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/session/HiveSessionImpl.scala +++ b/externals/kyuubi-hive-sql-engine/src/main/scala/org/apache/kyuubi/engine/hive/session/HiveSessionImpl.scala @@ -31,6 +31,7 @@ import org.apache.kyuubi.events.EventBus import org.apache.kyuubi.operation.{Operation, OperationHandle} import org.apache.kyuubi.session.{AbstractSession, SessionHandle, SessionManager} import org.apache.kyuubi.shaded.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue, TProtocolVersion} +import org.apache.kyuubi.util.reflect.{DynFields, DynMethods} class HiveSessionImpl( protocol: TProtocolVersion, @@ -63,7 +64,22 @@ class HiveSessionImpl( case TGetInfoType.CLI_SERVER_NAME => TGetInfoValue.stringValue("Hive") case TGetInfoType.CLI_DBMS_NAME => TGetInfoValue.stringValue("Apache Hive") case TGetInfoType.CLI_DBMS_VER => TGetInfoValue.stringValue(HiveVersionInfo.getVersion) - case TGetInfoType.CLI_ODBC_KEYWORDS => TGetInfoValue.stringValue("Unimplemented") + case TGetInfoType.CLI_ODBC_KEYWORDS => + try { + // HIVE-17765 expose Hive keywords. + // exclude these keywords to be consistent with Hive behavior. + val excludes = DynFields.builder() + .hiddenImpl("org.apache.hive.service.cli.session.HiveSessionImpl", "ODBC_KEYWORDS") + .buildStaticChecked[util.Set[String]]().get() + val keywords = DynMethods.builder("getKeywords") + .impl("org.apache.hadoop.hive.ql.parse.ParseUtils", classOf[util.Set[String]]) + .buildStaticChecked() + .invoke[String](excludes) + TGetInfoValue.stringValue(keywords) + } catch { + case _: ReflectiveOperationException => + TGetInfoValue.stringValue("Unimplemented") + } case TGetInfoType.CLI_MAX_COLUMN_NAME_LEN | TGetInfoType.CLI_MAX_SCHEMA_NAME_LEN | TGetInfoType.CLI_MAX_TABLE_NAME_LEN => TGetInfoValue.lenValue(128) diff --git a/integration-tests/kyuubi-hive-it/src/test/scala/org/apache/kyuubi/it/hive/operation/KyuubiOperationHiveEnginePerUserSuite.scala b/integration-tests/kyuubi-hive-it/src/test/scala/org/apache/kyuubi/it/hive/operation/KyuubiOperationHiveEnginePerUserSuite.scala index 3f9465b37..fd9e76bc3 100644 --- a/integration-tests/kyuubi-hive-it/src/test/scala/org/apache/kyuubi/it/hive/operation/KyuubiOperationHiveEnginePerUserSuite.scala +++ b/integration-tests/kyuubi-hive-it/src/test/scala/org/apache/kyuubi/it/hive/operation/KyuubiOperationHiveEnginePerUserSuite.scala @@ -61,6 +61,20 @@ class KyuubiOperationHiveEnginePerUserSuite extends WithKyuubiServer with HiveEn } } + test("[KYUUBI #5865] Hive engine CLI_ODBC_KEYWORDS") { + withSessionConf(Map(KyuubiConf.SERVER_INFO_PROVIDER.key -> "ENGINE"))()() { + withSessionHandle { (client, handle) => + val req = new TGetInfoReq() + req.setSessionHandle(handle) + req.setInfoType(TGetInfoType.CLI_ODBC_KEYWORDS) + val value = client.GetInfo(req).getInfoValue.getStringValue + assert(value.contains("DATABASE") || value === "Unimplemented") + // excluded keywords + assert(!value.contains("ADD")) + } + } + } + test("kyuubi defined function - system_user, session_user") { withJdbcStatement("hive_engine_test") { statement => val rs = statement.executeQuery("SELECT system_user(), session_user()")