Skip to content

Commit f10df51

Browse files
[KYUUBI #7305][FOLLOWUP] Skip Hive protocol "default" stub in session open
The Hive JDBC driver sends `USE_DATABASE = "default"` when the user did not specify a database in the connection URL — a protocol-level stub indistinguishable from a genuine request for a database literally named "default". Forwarding that into `setSchema` plus recording it as `effectiveDatabase` caused PG and ClickHouse metadata operations to scope to a non-existent or unintended schema, breaking the existing `get tables` suites in CI. Filter `"default"` at the session entry point: skip both the dialect `setSchema` call and the `effectiveDatabase` assignment for it. Drops the prior try/catch that only existed to tolerate the failure path. Also rewords the in-tree `MySQLDialect.setSchema` comment to describe the externally observed behavior of the documented `databaseTerm` connection property, without paraphrasing driver internals. URL paths that name a real non-`default` database keep the new scoping behavior; URL paths that explicitly name `default` continue to behave as before this PR (no metadata scope), which is the same as URL paths with no database — there is no observable regression.
1 parent a487d97 commit f10df51

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/MySQLDialect.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ class MySQLDialect extends JdbcDialect {
151151
}
152152

153153
override def setSchema(conn: Connection, schema: String): Unit = {
154-
// mysql-connector-j makes setCatalog/setSchema mutually exclusive based on the
155-
// `databaseTerm` connection property: with the default CATALOG, setCatalog issues
156-
// COM_INIT_DB and setSchema is a silent no-op; with SCHEMA it is the inverse.
157-
// Calling both means exactly one fires regardless of how the user configured the
158-
// URL. StarRocksDialect / DorisDialect inherit this via MySQLDialect.
154+
// The MySQL Connector/J `databaseTerm` connection property selects which of
155+
// setCatalog / setSchema actually switches the session database; the other
156+
// call returns without effect for that mode (verified by black-box testing
157+
// and consistent with the reference manual). Invoking both ensures the
158+
// database is switched regardless of how the user configured the URL.
159+
// StarRocksDialect / DorisDialect inherit this via MySQLDialect.
159160
conn.setCatalog(schema)
160161
conn.setSchema(schema)
161162
}

externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.apache.kyuubi.engine.jdbc.session
1919
import java.sql.{Connection, DatabaseMetaData}
2020

2121
import scala.util.{Failure, Success, Try}
22-
import scala.util.control.NonFatal
2322

2423
import org.apache.kyuubi.KyuubiSQLException
2524
import org.apache.kyuubi.config.KyuubiConf
@@ -50,8 +49,10 @@ class JdbcSessionImpl(
5049
/**
5150
* The database the client requested via `USE_DATABASE` at session open. Used by
5251
* `JdbcOperationManager` as the metadata schema filter. `None` when no `USE_DATABASE`
53-
* was requested, or when the request was for "default" (the Hive JDBC driver's fallback)
54-
* and the dialect's `setSchema` call failed.
52+
* was requested, or when the request was the literal `"default"`. The Hive JDBC
53+
* driver sends `"default"` as a protocol stub when the user did not specify a
54+
* database in the URL, so it cannot be distinguished from a genuine request and
55+
* is treated as "no scope".
5556
*/
5657
private[jdbc] var effectiveDatabase: Option[String] = None
5758

@@ -77,17 +78,13 @@ class JdbcSessionImpl(
7778
sessionConf,
7879
sessionConnection,
7980
sessionConf.get(ENGINE_JDBC_SESSION_INITIALIZE_SQL))
80-
conf.get(USE_DATABASE).foreach { database =>
81-
try {
82-
JdbcDialects.get(sessionConf).setSchema(sessionConnection, database)
83-
effectiveDatabase = Some(database)
84-
} catch {
85-
case NonFatal(e) if database == "default" =>
86-
// The Hive JDBC driver sends "default" when the user didn't specify a database
87-
// in the connection URL. Tolerate USE failure in that case so the session can
88-
// still open against backends that have no "default" database.
89-
warn(s"Failed to switch to database 'default', ignored.", e)
90-
}
81+
// The Hive JDBC driver sends `"default"` as USE_DATABASE when the user did not
82+
// specify a database in the URL: a protocol stub indistinguishable from a real
83+
// request. Filter it here so we don't push a non-existent / unintended schema
84+
// filter into metadata operations on backends without a `default` database.
85+
conf.get(USE_DATABASE).filter(_ != "default").foreach { database =>
86+
JdbcDialects.get(sessionConf).setSchema(sessionConnection, database)
87+
effectiveDatabase = Some(database)
9188
}
9289
super.open()
9390
info(s"The jdbc session is started.")

0 commit comments

Comments
 (0)