wangzhigang1999 commented on code in PR #7419:
URL: https://github.com/apache/kyuubi/pull/7419#discussion_r3152120945


##########
externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/JdbcDialect.scala:
##########
@@ -82,6 +82,20 @@ abstract class JdbcDialect extends SupportServiceLoader with 
Logging {
 
   def getSchemaHelper(): SchemaHelper
 
+  /**
+   * Switch the current database on the backend connection.
+   *
+   * Called during session open when the client specified a database in the 
connection URL
+   * (populated by the Hive JDBC driver into `USE_DATABASE`). Dialects that 
support an
+   * in-session database context switch (e.g. MySQL's `USE db`) should 
override this and
+   * return `true` on success; the default is a no-op that returns `false`, 
meaning the
+   * backend has no notion of "current database" that applies to this session.
+   *
+   * The return value is used by `JdbcOperationManager` to decide whether the 
requested
+   * database can be treated as the effective schema filter for metadata 
operations.
+   */
+  def setCurrentDatabase(connection: Connection, database: String): Boolean = 
false

Review Comment:
   Update — went with **Option B** and pushed it as ff518412e.
   
   `MySQLDialect.setCurrentDatabase` now calls 
`connection.setCatalog(database)` followed by `connection.setSchema(database)` 
instead of executing `USE` ourselves. `JdbcDialect`'s default stays a no-op 
returning `false`, and no other dialect is touched.
   
   Why B over A:
   - Goes through JDBC standard API, addressing the spirit of your review — no 
more hand-rolled SQL, no backtick escaping concerns.
   - Engages the driver's internal hooks (`useLocalSessionState` cache, 
`ConnectionLifecycleInterceptor`) so connection state stays coherent.
   - Double-call cost is effectively zero: under any `databaseTerm`, the 
non-matching branch is `if (false) return` with no network IO.
   - Functionally equivalent for MySQL / StarRocks / Doris — verified locally 
with DBeaver: logs show `catalog=null → catalog=doctor`, confirming 
`setCatalog` actually sends `COM_INIT_DB`.
   
   Why I didn't extend `setSchema` to the default impl for other dialects: 
Phoenix / Impala drivers are likely to throw `SQLFeatureNotSupportedException` 
from `setSchema`, which would regress session open. Keeping the change scoped 
to MySQL family.
   
   Also added three StarRocks regression tests covering URL-scoped getTables, 
no-filter when URL has no db, and session-open failure on a non-existent db.
   
   PTAL.
   



-- 
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]

Reply via email to