Repository navigation
fix(metadata): treat list_tables catalog as a LIKE pattern - #199
Conversation
There was a problem hiding this comment.
Verdict: 1 Nit
Looks good — a well-scoped, correct fix that types list_tables's catalog as a LikePattern and reproduces Thrift's catalog-wildcarding client-side (IN ALL CATALOGS + TABLE_CAT filter) while keeping the literal fast path. The wildcard/literal routing, the requested_catalog vs catalog_filter split, and all binding call sites (napi/pyo3/c_abi/e2e/lib.rs) are consistent, and the helpers + reshape path are unit-tested including the issue-#129 underscore repro. Only a doc nit on the LIKE matcher; no correctness or contract concerns.
Other findings
- ⚪ Nit — The
%arm comment says it will "Collapse consecutive%", but the code doesn't collapse runs of%— it recurses intolike_match_inner(rest, ...)at every suffix, and ifrestbegins with another%that inner call repeats the same fan-out. Matching is still correct, but the claimed optimization isn't present, so a pattern with many consecutive/interleaved%against a long non-matching candidate can backtrack super-linearly. In practice catalog names and patterns are capped at 255 bytes and this only runs on catalog values, so the cost is bounded and negligible — this is purely a comment/behavior mismatch worth tidying (either actually collapse consecutive%, or drop the 'Collapse' wording).
msrathore-db
left a comment
There was a problem hiding this comment.
I'm afraid there would be a high usage of _ in catalog name where the latency would account for SHOW TABLES IN ALL CATALOGS which would be extremely slow
One alternative I can suggest is to do a SHOW CATALOGS and filter and call show tables for each of them. I think that would be a faster alternative
958ac0d to
39eb85a
Compare
|
Good call, @msrathore-db — adopted. The wildcard-catalog path no longer does
This avoids the whole-workspace table scan for selective patterns, exactly as you suggested. Two related notes:
Also addressed the peco-review-bot nit (dropped the inaccurate "Collapse consecutive %" comment on the matcher). Updated tests: unit (matcher/escapes/merge-sort), wiremock asserting the emitted SQL per routing path (literal |
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested fix for treating the list_tables catalog as a LIKE pattern — good wiremock + unit + e2e coverage, and the Identifier→LikePattern signature change is propagated consistently across bindings. One medium issue: the fan-out path leaks server-side statements on read/reshape error paths (bypasses close_statement). One low doc/code mismatch on the wildcard-catalog strategy.
39eb85a to
2d42ec2
Compare
ODBC `SQLTables` treats `CatalogName` as a pattern-value argument under the default `SQL_ATTR_METADATA_ID = SQL_FALSE`, and the Thrift protocol backs this: `TGetTablesReq.catalogName` is a `TPatternOrIdentifier`, so the server wildcards `_` / `%` in the catalog. The kernel's SEA `SHOW` path typed the catalog as an exact `Identifier`, silently dropping the wildcard — a caller passing `comparator_tests` got only that catalog, not the sibling `comparator-tests` a `_` should match. The Databricks `SHOW` grammar has no catalog-pattern position (the `LIKE` clause applies only to schema/table names). Rather than `SHOW TABLES IN ALL CATALOGS` + client-side row filtering — which scans every table in every catalog on the workspace and discards the non-matches — `list_tables` now resolves a wildcard catalog by enumerating catalogs and fanning out one scoped query per match: - Wildcard catalog (`_` / `%`, or a `*`/empty literal the `SHOW` builder would misread as "all catalogs"): `SHOW CATALOGS`, filter the names with a case-insensitive `LikeMatcher`, then run `SHOW TABLES IN CATALOG <name>` for each match with bounded parallelism (schema/table/type pushed down server-side). Results are concatenated and re-sorted into the JDBC row order. - Literal catalog (no active wildcards, incl. the ODBC `SQL_ATTR_METADATA_ID = SQL_TRUE` identifier case): unescape and scope server-side via `SHOW TABLES IN CATALOG <name>` — the fast exact path. - Empty catalog pattern: "match nothing" per `LikePattern` — an empty result with no wire call (matches the schema/table `LIKE ''` convention rather than silently broadening to all catalogs). - `None`: a single `SHOW TABLES IN ALL CATALOGS` — genuinely "every catalog", the cheapest correct query. The per-catalog fan-out is strictly cheaper than a whole-workspace scan for selective patterns (per PR review feedback), and because each query is catalog-scoped it also sidesteps the pre-DBR-16 case where `SHOW TABLES IN ALL CATALOGS` omits `catalogName` and rows can't be attributed to a catalog. An object-not-found on a per-catalog query (catalog dropped mid-enumeration) contributes zero rows, per the JDBC empty-result contract. Scope is `list_tables` only. `list_columns` and `list_schemas` keep an exact catalog identifier, matching their Thrift request fields (`TGetColumnsReq.catalogName` / `TGetSchemasReq.catalogName` are both `TIdentifier`, which "must not contain a search pattern"). Adds `pattern_has_wildcards` / `strip_jdbc_escapes` / `is_wildcard_or_empty_scope` helpers and a compiled, reusable `LikeMatcher` to the SQL builder; unit tests (matcher, escapes, merge-sort across catalogs); wiremock tests asserting the emitted SQL per routing path (literal `IN CATALOG`, wildcard fan-out, empty match-nothing); and a live-workspace e2e regression test. Wrapper call sites (pyo3 / napi / C ABI) updated for the `Identifier` -> `LikePattern` signature change. Fixes databricks/databricks-odbc#129 Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
2d42ec2 to
35c0e07
Compare
|
Addressed the review-round findings (pushed 35c0e07): Behavior
Docs / cross-binding
Observability
Cleanup
Tests (all green: 716 lib + 21 wiremock + 10 live e2e)
PTAL. |
There was a problem hiding this comment.
Verdict: 1 Low · 1 Nit
Looks good — a solid, well-tested fix that correctly retypes the list_tables catalog as a LIKE pattern and resolves wildcards via enumerate-then-fan-out. Routing, escaping, and match-arm ordering are consistent, and wiremock coverage (fan-out, dropped-catalog tolerance, error propagation, >8 in-flight cap, empty/percent) is thorough. One low-severity resource-lifecycle note on statement cleanup when a per-catalog error aborts the fan-out, plus a doc-duplication nit.
Other findings
- ⚪ Nit —
sort_tables_batch(new pub(crate) wrapper) carries a doc comment identical to the privatesort_tablesit delegates to, so the two blocks are verbatim duplicates. Consider makingsort_tablesitselfpub(crate)(or having the wrapper's doc just say 'see [sort_tables]') to avoid the copy-paste drift risk.
| ) | ||
| .await | ||
| } | ||
| // Literal catalog: scope server-side (fast path). Unescape |
There was a problem hiding this comment.
🔵 Low — When a per-catalog fetch returns a non-not-found error, result? aborts the whole call and the FuturesUnordered (inflight) is dropped along with any still-pending sibling futures. fetch_tables_for_catalog creates a server-side statement (via transport().list_tables) and only closes it at the end of its own body; a future cancelled after its create request completed but before reaching close_statement leaks that statement server-side. This is the exact edge the repo's resource-lifecycle convention targets ('server-side handles/sessions/streams closed on every path (incl. error/early-return)'). The window is narrow and error-abort is exceptional, so severity is low, but it's worth noting since the happy/in-future error paths were deliberately hardened here while the cross-future abort path was not. A structured cleanup (e.g. draining inflight to completion on error before returning, discarding rows) would close them deterministically.
msrathore-db
left a comment
There was a problem hiding this comment.
Please do a quick benchmarking on arca US West 2 if possible and mention the perf diff in the PR descripion for future use
|
Merge-queue update: the driver-test compile break is resolved (databricks-driver-test#962, merged) and the refreshed replay tapes pass for 30/31 metadata tests. The one remaining failure, Keeping the kernel fan-out parallel is the right call — serializing it just to satisfy the harness would slow real metadata calls. So the test is replay-skipped in databricks-driver-test#967 with a follow-up to extend the harness's order-independent matching to SEA statements. Once #967 lands, this merge queue should go green. |
Summary
Metadata::list_tablestyped thecatalogargument as an exactIdentifier, so ODBCSQLTables(and the other bindings) silently dropped_/%wildcards in the catalog. A caller passingcomparator_testsgot only that catalog and not the siblingcomparator-teststhat_should match — the divergence reported in databricks/databricks-odbc#129 (OSS 4 rows vs reference 8 rows).This is a real bug: ODBC
SQLTablestreatsCatalogNameas a pattern-value argument under the defaultSQL_ATTR_METADATA_ID = SQL_FALSE, and the Thrift protocol backs it —TGetTablesReq.catalogNameis aTPatternOrIdentifier, so the server wildcards the catalog. The reference (Simba/Thrift) driver gets the extra rows that way.What the server supports, and how the fix resolves a wildcard
The Databricks SEA
SHOWgrammar (which this kernel uses) has no catalog-pattern position — theLIKEclause applies only to schema/table names; the catalog is alwaysIN CATALOG <exact>orIN ALL CATALOGS. Rather thanSHOW TABLES IN ALL CATALOGS+ client-side row filtering (which scans every table in every catalog on the workspace and throws away the non-matches),list_tablesresolves a wildcard catalog by enumerating catalogs and fanning out one scoped query per match:_/%unescaped, or a*/empty literal theSHOWbuilder would misread as "all catalogs") →SHOW CATALOGS, filter the catalog names client-side with a case-insensitiveLikeMatcher, thenSHOW TABLES IN CATALOG <name>per match (schema/table/type pushed down server-side) with bounded parallelism (cap 8 in flight). Results are concatenated and re-sorted into the JDBC row order.SQL_ATTR_METADATA_ID = SQL_TRUEidentifier case) → unescape and scope server-side viaSHOW TABLES IN CATALOG <name>(fast exact path).Some("")) → "match nothing" perLikePattern(mirrors the schema/tableLIKE ''convention) → empty result, no wire call.None→ a singleSHOW TABLES IN ALL CATALOGS— genuinely "every catalog", the cheapest correct query.Why fan-out instead of a whole-workspace scan
The per-catalog fan-out is strictly cheaper than
SHOW TABLES IN ALL CATALOGSfor selective catalog patterns (raised in review by @msrathore-db), and the common single-catalog case never hits it at all — a BI tool targeting one catalog named e.g.my_catalogeither setsSQL_ATTR_METADATA_ID = SQL_TRUEor escapes the_, both of which take the fast exact path. Because each fan-out query is catalog-scoped, it also sidesteps the pre-DBR-16 edge whereIN ALL CATALOGSomitscatalogNameand rows can't be attributed to a catalog. An object-not-found on a per-catalog query (catalog dropped mid-enumeration) contributes zero rows, per the JDBC empty-result contract.Scope:
list_tablesonlyThe catalog contract is per-call, grounded in the Thrift IDL:
list_tablesTGetTablesReq.catalogNameTPatternOrIdentifierLikePattern✅list_columnsTGetColumnsReq.catalogNameTIdentifierlist_schemasTGetSchemasReq.catalogNameTIdentifierThe issue's suspicion that
SQLColumnsis affected identically does not hold — the ThriftTGetColumnsReq.catalogNameis aTIdentifierthat "must not contain a search pattern", so Simba doesn't wildcard the columns catalog either. Keeping columns/schemas exact preserves JDBC-spec semantics for Python / Node / ADBC on the shared kernel.Changes
sql.rs:pattern_has_wildcards,strip_jdbc_escapes,is_wildcard_or_empty_scopehelpers, and a compiled, reusableLikeMatcher(case-insensitive ODBC/JDBC LIKE) used to filter catalog names (+ unit tests).metadata_v0.rs:list_tablescatalog is nowOption<LikePattern>, with routing across the exact / fan-out / empty / all-catalogs paths above; adds the enumerate-then-fan-out with bounded parallelism.thrift_shape.rs:reshape_tablesis back to its 3-arg form (catalog matching moved to the name level, so the client-side row filter was removed); exposessort_tables_batchso the fan-out can re-sort the merged cross-catalog result.c_abi/pyo3/napi: call sites updated for theIdentifier→LikePatternsignature change.IN CATALOG, wildcard fan-out viaSHOW CATALOGS+ per-catalogIN CATALOG, empty match-nothing), and a self-adapting live-workspace e2e regression test.Testing
cargo fmt --all+cargo clippy --all-targets -- -D warnings: clean.s_mplespattern drivesSHOW CATALOGS+ per-catalogSHOW TABLES IN CATALOG samplesand returns rows, all matchingTABLE_CAT).Note: run with
--no-default-features --features tls-rustls— the defaulttls-nativefails to link in this environment due to a pre-existing system OpenSSL 1.1-vs-3.x symbol mismatch, unrelated to this change.Fixes databricks/databricks-odbc#129
This pull request and its description were written by Isaac.