Skip to content

fix(metadata): literal catalog wildcard and null foreign table conformance - #231

Merged
vikrantpuppala merged 2 commits into
mainfrom
fix/metadata-catalog-tabletypes-crossref
Aug 10, 2026
Merged

vikrantpuppala merged 2 commits into
mainfrom
fix/metadata-catalog-tabletypes-crossref

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Summary

Fixes a cluster of SEA metadata conformance findings from the multi-language coverage fan-out. All target behavior was verified against the reference-driver ground truth (adbc-drivers/databricks #594 for catalog scoping, #609 for cross-reference) — not just the issue's stated "expected".

The findings resolve to two code fixes plus one already-fixed-on-main finding:

1. Catalog match-all wildcard broadened to "all catalogs" (#202, #221 — METADATA-036/037)

SqlCommandBuilder::build_show_schemas / build_show_tables decided SHOW … IN ALL CATALOGS via is_null_or_wildcard(&self.catalog), which returned true for a literal catalog %, *, or "". By the time a catalog reaches these builders as Some(name), it is already a resolved literal (an exact Identifier, or a \% unescaped by strip_jdbc_escapes to %) — so a literal % was silently broadened to every catalog instead of matching nothing.

Fix: the builders now broaden to "all catalogs" only when the catalog is None (mirroring the already-correct build_show_columns). A literal % / * / "" is scoped verbatim (SHOW … IN [CATALOG] \%``) and matches no real catalog → 0 rows, and the server's object-not-found maps to an empty result.

  • An unescaped % LikePattern on list_tables is still genuinely match-all (one SHOW TABLES IN ALL CATALOGS) — the v0 routing resolves it to None before the builder. Guarded by the existing list_tables_percent_catalog_uses_single_all_catalogs_query test, still green.
  • ODBC unaffected: the C ABI already normalizes NULL / "" / whitespace catalog to None ("all catalogs"), which is the actual ODBC convention. Only a literal % / * (which ODBC does not use for "all") changes, now to the correct 0-row result.

2. foreign_keys with a NULL foreign table errored instead of returning empty (#212 — METADATA-037/038)

Metadata::foreign_keys rejected a None foreign_table with InvalidArgument. Per the JDBC SEA listCrossReferences contract (which keys solely off the foreign table) an unspecified foreign table means "nothing to look up".

Fix: a None foreign_table now returns an empty result (0 rows, no SHOW FOREIGN KEYS / ExecuteStatement), covering both the parent-set case (METADATA-037) and the both-tables-null case (METADATA-038, where SEA follows JDBC SEA rather than Thrift's 42000). This is also the ODBC primary-keys-only SQLForeignKeys form. foreign_catalog / foreign_schema remain required only when a foreign_table is supplied.

3. Empty table_types filter (#204, and #212's METADATA-035) — already fixed on main

reshape_tables already treats Some(&[]) the same as None (match all types), with the tables_empty_types_matches_all unit test asserting it. No code change needed; this PR closes the tracking issue.

Downstream / ODBC impact

Per the request to confirm the C ABI / ODBC path: the C ABI's NULL/"" → "all catalogs" normalization and the empty-table_types → "all types" convention are both unchanged. The header (include/databricks_kernel.h) and C ABI doc comments for foreign_keys were updated to document the new NULL-foreign-table → empty-result contract.

Test plan

  • cargo test (full suite incl. doc tests), cargo clippy --all-targets -- -D warnings, cargo +stable fmt --all — all green.
  • New wiremock tripwire tests:
    • list_schemas_literal_percent_catalog_scopes_verbatim_and_empties
    • list_tables_escaped_percent_catalog_scopes_verbatim_and_empties
    • foreign_keys_null_foreign_table_returns_empty_without_wire_call
    • foreign_keys_both_tables_null_returns_empty_without_wire_call
  • New builder unit tests asserting literal % / * / "" catalog scopes verbatim (test_show_schemas_literal_percent_catalog_scopes_verbatim, test_show_tables_literal_percent_catalog_scopes_verbatim, …).
  • Existing match-all regression guard (list_tables_percent_catalog_uses_single_all_catalogs_query) still passes.

Closes #202
Closes #204
Closes #212
Closes #221

This pull request and its description were written by Isaac.

…mance

Two SEA metadata conformance fixes surfaced by the multi-language
coverage fan-out, verified against the reference driver behavior:

- Catalog match-all wildcard (METADATA-036/037, #202, #221): a literal
  catalog `%`, `*`, or `""` reaching `build_show_schemas` /
  `build_show_tables` was broadened to `SHOW … IN ALL CATALOGS`. It now
  scopes verbatim (`SHOW … IN [CATALOG] \`%\``) and matches nothing (0
  rows), mirroring the `build_show_columns` `Option`-based decision.
  Only a `None` catalog means "all catalogs". This makes an escaped `\%`
  catalog and an exact `Identifier("%")` return the correct empty
  result. An unescaped `%` `LikePattern` on `list_tables` is still
  match-all, and the C ABI NULL/"" → "all catalogs" convention is
  unchanged.

- foreign_keys unspecified foreign table (METADATA-037/038, #212):
  `Metadata::foreign_keys` with a `None` foreign_table now returns an
  empty result (0 rows, no `SHOW FOREIGN KEYS` issued) instead of an
  `InvalidArgument` error, matching the JDBC SEA `listCrossReferences`
  contract and the ODBC primary-keys-only `SQLForeignKeys` form (covers
  the parent-set and both-tables-null cases). foreign_catalog /
  foreign_schema stay required only when a foreign_table is supplied.

Updates the C ABI header and doc comments to match, and adds wiremock
tripwire tests (literal/escaped `%` catalog scopes verbatim and empties;
null and both-null foreign table return empty with zero ExecuteStatement
calls) plus builder unit tests. The empty `table_types` filter finding
(METADATA-035, #204) was already fixed on main.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
…mas/list_tables

The transport trait docs still said "When catalog is None or wildcard,
uses SHOW … IN ALL CATALOGS". After the catalog-scoping fix only `None`
broadens to all catalogs; a `Some` catalog (including a literal `%` /
`*` / `""`) is scoped verbatim and matches no real catalog. Doc-only.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

Merged via the queue into main with commit 1ec4248 Aug 10, 2026
18 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — ebac08dd Deployed Aug 10, 2026 by vikrantpuppala via review #110
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant