Skip to content

Use SHOW COLUMNS IN ALL CATALOGS for getColumns with null catalog - #1576

Closed
msrathore-db wants to merge 2 commits into
databricks:mainfrom
msrathore-db:fix/getcolumns-show-columns-all-catalogs
Closed

msrathore-db wants to merge 2 commits into
databricks:mainfrom
msrathore-db:fix/getcolumns-show-columns-all-catalogs

Conversation

@msrathore-db

Copy link
Copy Markdown
Collaborator

Summary

DatabaseMetaData.getColumns(catalog=null, ...) previously enumerated every catalog with SHOW CATALOGS and then issued a separate SHOW COLUMNS IN CATALOG \`for each one, fanning the calls out across a metadata thread pool. This predates the server-side support forSHOW ... IN ALL CATALOGS, which getSchemasandgetTables` already use for the null-catalog case.

This PR makes getColumns consistent with the other metadata calls: when the catalog is null, the driver now emits a single SHOW COLUMNS IN ALL CATALOGS statement (plus the usual SCHEMA LIKE / TABLE LIKE / column LIKE clauses) and lets the server enumerate catalogs in one round trip.

Details

  • CommandConstants: add SHOW_COLUMNS_IN_ALL_CATALOGS_SQL.
  • CommandBuilder.fetchColumnsSQL: emit SHOW COLUMNS IN ALL CATALOGS when catalogName == null (mirrors fetchTablesSQL / fetchSchemaSQL); the LIKE-clause building is unchanged.
  • DatabricksMetadataQueryClient.listColumns: drop the up-front "enumerate catalogs" branch. The null-catalog request now goes through the normal path; on a parse syntax error (older DBR versions that don't support the syntax) it transparently falls back to the previous enumerate-and-fan-out behavior (fetchColumnsAcrossCatalogs), exactly like the listSchemas fallback.

The SHOW COLUMNS IN ALL CATALOGS result schema is identical to per-catalog SHOW COLUMNS — the catalogName column is populated per row — so COLUMN_COLUMNS mapping (TABLE_CAT ← catalogName) needs no changes.

Testing

  • Verified SHOW COLUMNS IN ALL CATALOGS SCHEMA LIKE '…' TABLE LIKE '…' succeeds against a real SQL warehouse and returns the expected 13-column schema with catalogName populated per row.
  • CommandBuilderTest: added null-catalog cases asserting SHOW COLUMNS IN ALL CATALOGS with and without LIKE clauses.
  • DatabricksMetadataQueryClientTest: added testListColumnsAllCatalogs (single-statement path, no catalog enumeration) and testListColumnsAllCatalogs_fallsBackOnParseSyntaxError (fallback to enumerate-and-fan-out).
  • Full metadata suites green: DatabricksMetadataQueryClientTest, CommandBuilderTest, MetadataResultSetBuilderTest, DatabricksSdkClientTest, DatabricksDatabaseMetaDataTest.

This pull request and its description were written by Isaac.

getColumns(null, ...) previously enumerated every catalog via SHOW
CATALOGS and issued a per-catalog SHOW COLUMNS, fanning out across a
thread pool. This mirrors the older getSchemas/getTables behavior that
has since moved to a single SHOW ... IN ALL CATALOGS statement.

This change makes getColumns consistent: a null catalog now emits a
single "SHOW COLUMNS IN ALL CATALOGS" statement (with the usual
SCHEMA/TABLE/column LIKE clauses), letting the server enumerate catalogs
in one call. The result schema is identical to per-catalog SHOW COLUMNS
(the catalogName column is populated per row), so no result-mapping
changes are needed.

Older DBR versions that don't support the syntax return a parse syntax
error, which is caught and transparently falls back to the previous
enumerate-and-fan-out path (matching the getSchemas fallback).

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <[email protected]>
@msrathore-db
msrathore-db requested a review from gopalldb July 24, 2026 08:31
msrathore-db added a commit that referenced this pull request Jul 28, 2026
…me-repo, integration-test verification) (#1580)

## Summary

Same change as #1576, pushed as a **same-repo branch** (not a fork) so
the integration-test gate runs with a write-scoped token. The fork PR
(#1576) had `skip-integration-tests-pr` fail with `403 Resource not
accessible by integration` purely because a fork's `GITHUB_TOKEN` is
read-only — this PR verifies the integration checks pass on a same-repo
branch.

`DatabaseMetaData.getColumns(catalog=null, ...)` now issues a single
`SHOW COLUMNS IN ALL CATALOGS` statement (consistent with
`getSchemas`/`getTables`) instead of enumerating every catalog and
issuing a per-catalog `SHOW COLUMNS`. Older DBR versions that don't
support the syntax fall back to the previous enumerate-and-fan-out
behavior on a parse syntax error.

## Details

- `CommandConstants`: add `SHOW_COLUMNS_IN_ALL_CATALOGS_SQL`.
- `CommandBuilder.fetchColumnsSQL`: emit `SHOW COLUMNS IN ALL CATALOGS`
when `catalogName == null` (mirrors `fetchTablesSQL` /
`fetchSchemaSQL`).
- `DatabricksMetadataQueryClient.listColumns`: null-catalog request goes
through the normal path; on a parse syntax error it falls back to
`fetchColumnsAcrossCatalogs`, exactly like `listSchemas`.

The `SHOW COLUMNS IN ALL CATALOGS` result schema is identical to
per-catalog `SHOW COLUMNS` (the `catalogName` column is populated per
row), verified against a real SQL warehouse, so `COLUMN_COLUMNS` mapping
needs no changes.

## Testing

- Verified `SHOW COLUMNS IN ALL CATALOGS SCHEMA LIKE '…' TABLE LIKE '…'`
succeeds against a real SQL warehouse and returns the expected 13-column
schema with `catalogName` populated per row.
- Added `CommandBuilderTest` null-catalog cases and
`DatabricksMetadataQueryClientTest` tests for both the single-statement
path and the parse-error fallback.
- Full metadata suites green locally.

This pull request and its description were written by Isaac.

Signed-off-by: Madhavendra Rathore <[email protected]>
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.

2 participants