wangzhigang1999 opened a new pull request, #7419: URL: https://github.com/apache/kyuubi/pull/7419
### Why are the changes needed? This is a bug fix. The Hive JDBC driver rewrites a `null` `schemaPattern` to `"%"` in `GetTables`, and the JDBC engine forwards it directly into `WHERE TABLE_SCHEMA LIKE '%'`, so DBeaver — which always passes `null` once a connection is established — sees tables from every database in the backend rather than the one in its connection URL. Compounding this, the JDBC engine never applies the URL-level database to the underlying JDBC connection, so there is no "current database" on the backend for a filter to fall back to. The fix introduces a dialect-level `setCurrentDatabase` hook, tracks an `effectiveDatabase` on the session, and routes blank/`"%"` schema patterns through it in `GetTablesOperation`. `MySQLDialect` additionally implements `getCatalogsOperation` / `getSchemasOperation` with JDBC-standard column labels (`TABLE_CATALOG` / `TABLE_SCHEM`) so the schemas tree in DBeaver populates correctly. Non-MySQL dialects inherit the default no-op `setCurrentDatabase` and `effectiveDatabase` stays `None`, so PostgreSQL / Oracle / etc. keep their existing behavior. Note: `getSchemas()` continues to return all accessible schemas per the JDBC spec — the URL-level database only affects the default query context and the blank/`"%"` fallback in `getTables`. This matches the behavior of the native MySQL JDBC driver. Clients that want to restrict the visible schema list should do so via client-side filters (e.g. DBeaver's "Schemas" filter). ### How was this patch tested? Added unit / integration tests in `MySQLOperationSuite` covering: - `getTables` with a database in the URL returns only that database's tables - `getTables` with a `"%"` schema pattern is routed to the session's effective database - `getSchemas` returns results with JDBC-standard `TABLE_CATALOG` / `TABLE_SCHEM` column labels - `getCatalogs` behavior Also verified end-to-end against a live StarRocks backend using Spark's Hive-JDBC beeline: ``` # URL with a database → only that database's tables jdbc:hive2://127.0.0.1:10009/doctor → !tables : 3 rows, all TABLE_SCHEMA=doctor jdbc:hive2://127.0.0.1:10009/information_schema → !tables : only information_schema views # URL without a database → previous no-filter behavior preserved jdbc:hive2://127.0.0.1:10009/ → !tables : tables from every database # DatabaseMetaData.getSchemas() returns JDBC-standard columns columns: TABLE_CATALOG, TABLE_SCHEM rows: def/doctor, def/information_schema, def/sys, ... ``` <img width="788" height="1194" alt="image" src="https://github.com/user-attachments/assets/ea0e3d6a-8ecc-4cf7-b7e8-6fb099f1f752" /> <img width="790" height="368" alt="image" src="https://github.com/user-attachments/assets/5f939c4f-902d-4526-8e26-2914bb99f109" /> ### Was this patch authored or co-authored using generative AI tooling? Human-authored core design and implementation. Tests, verification, and PR description drafting were assisted by Claude Code. Generated-by: Claude Code (Opus 4.7) Closes #7305. Supersedes the stale #7307 per @pan3793's suggestion there. Co-authored-by: zhzhenqin <[email protected]> -- 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]
