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


##########
externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/MySQLDialect.scala:
##########
@@ -122,6 +150,16 @@ class MySQLDialect extends JdbcDialect {
     query.toString()
   }
 
+  override def setSchema(conn: Connection, schema: String): Unit = {
+    // mysql-connector-j makes setCatalog/setSchema mutually exclusive based 
on the
+    // `databaseTerm` connection property: with the default CATALOG, 
setCatalog issues
+    // COM_INIT_DB and setSchema is a silent no-op; with SCHEMA it is the 
inverse.
+    // Calling both means exactly one fires regardless of how the user 
configured the
+    // URL. StarRocksDialect / DorisDialect inherit this via MySQLDialect.
+    conn.setCatalog(schema)
+    conn.setSchema(schema)

Review Comment:
   Good point to think through. The dual `setCatalog` + `setSchema` is safe 
because mysql-connector-j uses its `databaseTerm` connection property to select 
which of the two calls actually switches the session database; the other call 
returns without effect for that mode. So no matter how the user configured the 
URL, the StarRocks/Doris server only ever receives one "switch database" 
command, never two.
   
   Verified by black-box testing — under the default `CATALOG` setting, calling 
`setSchema` alone does not change the session database; under `SCHEMA`, calling 
`setCatalog` alone does not. Calling both is the safe path. The behavior is 
consistent with what the [MySQL Connector/J reference 
manual](https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html)
 documents about the property.
   
   The server treats the resulting "switch database" as exactly that — it does 
**not** treat it as "switch catalog" (catalog switching on StarRocks/Doris is a 
separate `SET CATALOG` SQL statement, not something the MySQL protocol 
exposes). The name we pass in comes from `USE_DATABASE`, which the Hive JDBC 
driver parses out of the URL path. The Hive URL syntax has no concept of 
catalog, so this name is always a database in the current (default) catalog.
   



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