pan3793 commented on code in PR #7442:
URL: https://github.com/apache/kyuubi/pull/7442#discussion_r3226549416
##########
externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/ImpalaDialect.scala:
##########
@@ -16,80 +16,40 @@
*/
package org.apache.kyuubi.engine.jdbc.dialect
-import java.util
+import java.sql.Connection
-import org.apache.commons.lang3.StringUtils
-
-import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.engine.jdbc.impala.{ImpalaSchemaHelper,
ImpalaTRowSetGenerator}
import org.apache.kyuubi.engine.jdbc.schema.{JdbcTRowSetGenerator,
SchemaHelper}
-import org.apache.kyuubi.session.Session
class ImpalaDialect extends JdbcDialect {
- override def getTablesQuery(
- catalog: String,
- schema: String,
- tableName: String,
- tableTypes: util.List[String]): String = {
- if (isPattern(schema)) {
- throw KyuubiSQLException.featureNotSupported("Pattern-like schema names
not supported")
- }
-
- val query = new StringBuilder("show tables ")
-
- if (StringUtils.isNotEmpty(schema) && !isWildcardSetByKyuubi(schema)) {
- query.append(s"in $schema ")
- }
-
- if (StringUtils.isNotEmpty(tableName)) {
- query.append(s"like '${toImpalaRegex(tableName)}'")
- }
-
- query.toString()
+ // The JDBC engine talks to Impalad via `KyuubiHiveDriver` (see
`ImpalaConnectionProvider`,
+ // chosen for its fixed `getMoreResults()` behavior).
`KyuubiConnection#setSchema` ships a
+ // Kyuubi-private session config (`kyuubi.operation.set.current.database`)
that Impalad
+ // does not recognize and rejects with "Invalid query option". Issue `USE`
directly so the
+ // database switch lands as plain Impala SQL the backend understands.
+ override def setSchema(conn: Connection, schema: String): Unit = {
+ val escaped = schema.replace("`", "``")
+ val stmt = conn.createStatement()
+ try stmt.execute(s"USE `$escaped`")
+ finally stmt.close()
}
- override def getColumnsQuery(
- session: Session,
- catalogName: String,
- schemaName: String,
- tableName: String,
- columnName: String): String = {
- if (StringUtils.isEmpty(tableName)) {
- throw KyuubiSQLException("Table name should not be empty")
- }
-
- if (isPattern(schemaName)) {
- throw KyuubiSQLException.featureNotSupported("Pattern-like schema names
not supported")
- }
-
- if (isPattern(tableName)) {
- throw KyuubiSQLException.featureNotSupported("Pattern-like table names
not supported")
- }
-
- val query = new StringBuilder("show column stats ")
-
- if (StringUtils.isNotEmpty(schemaName) &&
!isWildcardSetByKyuubi(schemaName)) {
- query.append(s"$schemaName.")
- }
-
- query.append(tableName)
- query.toString()
+ // Symmetric to `setSchema`: `KyuubiConnection#getSchema` ships a
Kyuubi-private session
+ // config (`kyuubi.operation.get.current.database`) that Impalad rejects.
Read the current
+ // database via plain SQL.
+ override def getCurrentSchema(conn: Connection): String = {
+ val stmt = conn.createStatement()
+ try {
+ val rs = stmt.executeQuery("SELECT current_database()")
+ try if (rs.next()) rs.getString(1) else null
+ finally rs.close()
+ } finally stmt.close()
Review Comment:
there are a few utilities method in `JdbcUtils` can simplify the code
##########
externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteMetaDataOperation.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kyuubi.engine.jdbc.operation
+
+import java.sql.{Connection, ResultSet}
+
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.engine.jdbc.dialect.JdbcDialect
+import org.apache.kyuubi.engine.jdbc.schema.Schema
+import org.apache.kyuubi.engine.jdbc.session.JdbcSessionImpl
+import org.apache.kyuubi.engine.jdbc.util.ResultSetFetchIterator
+import org.apache.kyuubi.operation.FetchOrientation.{FETCH_NEXT,
FetchOrientation}
+import org.apache.kyuubi.operation.OperationState
+import org.apache.kyuubi.operation.OperationState.OperationState
+import org.apache.kyuubi.operation.log.OperationLog
+import org.apache.kyuubi.session.Session
+import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TFetchResultsResp
+
+/**
+ * Base class that streams the result of a `DatabaseMetaData.getXxx(...)` call
against the
+ * session connection. Subclasses fix the particular metadata RPC via
[[runMetaDataCall]].
+ */
+abstract class ExecuteMetaDataOperation(session: Session) extends
JdbcOperation(session) {
Review Comment:
ExecuteMetaDataOperation => MetaDataOperation
##########
externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/operation/ExecuteMetaDataOperation.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kyuubi.engine.jdbc.operation
+
+import java.sql.{Connection, ResultSet}
+
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.engine.jdbc.dialect.JdbcDialect
+import org.apache.kyuubi.engine.jdbc.schema.Schema
+import org.apache.kyuubi.engine.jdbc.session.JdbcSessionImpl
+import org.apache.kyuubi.engine.jdbc.util.ResultSetFetchIterator
+import org.apache.kyuubi.operation.FetchOrientation.{FETCH_NEXT,
FetchOrientation}
+import org.apache.kyuubi.operation.OperationState
+import org.apache.kyuubi.operation.OperationState.OperationState
+import org.apache.kyuubi.operation.log.OperationLog
+import org.apache.kyuubi.session.Session
+import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TFetchResultsResp
+
+/**
+ * Base class that streams the result of a `DatabaseMetaData.getXxx(...)` call
against the
+ * session connection. Subclasses fix the particular metadata RPC via
[[runMetaDataCall]].
+ */
+abstract class ExecuteMetaDataOperation(session: Session) extends
JdbcOperation(session) {
+
+ protected def runMetaDataCall(dialect: JdbcDialect, conn: Connection):
ResultSet
Review Comment:
runMetaDataCall => fetchMetaData
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]