Skip to content

Fix getSchemas returning JDBC-escaped catalog name in SEA mode#1365

Open
gopalldb wants to merge 1 commit intodatabricks:mainfrom
gopalldb:fix/getschemas-catalog-escape
Open

Fix getSchemas returning JDBC-escaped catalog name in SEA mode#1365
gopalldb wants to merge 1 commit intodatabricks:mainfrom
gopalldb:fix/getschemas-catalog-escape

Conversation

@gopalldb
Copy link
Copy Markdown
Collaborator

@gopalldb gopalldb commented Apr 1, 2026

Summary

Fixes SEA/Thrift parity issue where getSchemas() returns comparator\_tests (with escaped underscore) instead of comparator_tests in the TABLE_CATALOG column when using SEA mode (useThriftClient=0).

Root Cause

In DatabricksMetadataQueryClient.listSchemas(), the catalog parameter from the JDBC caller can contain JDBC escape sequences (e.g., comparator\_tests where \_ escapes the _ wildcard). The CommandBuilder correctly strips these escapes for the SQL query (SHOW SCHEMAS IN \comparator_tests`), but the **original escaped value** was passed to getSchemasResult()`.

Since SHOW SCHEMAS IN \catalog`doesn't return acatalogcolumn from the server (onlySHOW SCHEMAS IN ALL CATALOGSdoes), the client falls back to populatingTABLE_CATALOG` from the passed parameter — inserting the JDBC-escaped value.

Fix

Strip JDBC escapes from the catalog parameter via WildcardUtil.stripJdbcEscapes() before passing it to getSchemasResult().

Verification

The EscapedUnderscoreTest in ../example can be used to verify end-to-end:

cd ../example
mvn exec:java -Dexec.mainClass="com.databricks.example.EscapedUnderscoreTest"

Expected: Both Thrift and SEA should return comparator_tests (without backslash) in TABLE_CATALOG for both escaped and unescaped input.

Test plan

  • New unit test: testListSchemasWithEscapedUnderscoreCatalog — verifies TABLE_CATALOG is unescaped
  • All 52 existing metadata query client tests pass
  • Manual verification with EscapedUnderscoreTest against live environment

This pull request was AI-assisted by Isaac.

@gopalldb gopalldb force-pushed the fix/getschemas-catalog-escape branch from e53de65 to 2dea12e Compare April 1, 2026 17:19
@gopalldb gopalldb force-pushed the fix/getschemas-catalog-escape branch from 2dea12e to bd8d83e Compare April 1, 2026 17:41
// Per JDBC spec, null foreign parameters means "don't filter on the foreign side."
// Since the SQL command can't express this, return an empty result set to match Thrift.
if (foreignCatalog == null || foreignSchema == null || foreignTable == null) {
LOGGER.debug(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change the level to warn to let user know that that null filter is not supported ?

…in getCrossReference

Two SEA/Thrift parity fixes:

1. getSchemas: Strip JDBC escapes and lowercase the catalog parameter
   before populating the TABLE_CATALOG result column. SHOW SCHEMAS IN
   `catalog` doesn't return a catalog column from the server, so the
   client populates it — but was using the raw JDBC-escaped value
   (e.g., "comparator\_tests" instead of "comparator_tests").

2. getCrossReference: Return empty result set when all three foreign
   key parameters (catalog, schema, table) are null, instead of
   throwing DatabricksValidationException. Matches Thrift server
   behavior which delegates to getExportedKeys (returns empty in DBSQL).

Note: Other null-catalog/null-schema parity gaps exist for
getCrossReference, getImportedKeys, and getPrimaryKeys when individual
parameters are null (Thrift resolves them to current catalog/schema via
the server). These need a broader auto-fill fix and are tracked separately.

Co-authored-by: Isaac
Signed-off-by: Gopal Lal <gopal.lal@databricks.com>
@gopalldb gopalldb force-pushed the fix/getschemas-catalog-escape branch from bd8d83e to 3aa4154 Compare April 1, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants