Repository navigation
fix(metadata): harden native metadata fallback coverage - #336
vuanhphung wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested change to request native Thrift metadata results with a legacy fallback. One medium concern: the native-tables catalog filter is case-sensitive (==) while the sibling cross-reference parent filter is case-insensitive, which can silently drop rows on the native path for mixed-case catalog inputs and diverge from the legacy SQL-scoped path. One low note about positional schema reattachment risking silent column mislabeling for all-Utf8 schemas if server column order ever drifts.
There was a problem hiding this comment.
Verdict: 1 Medium
Solid, well-tested change to request native Thrift metadata results with a clean legacy fallback. One medium concern: the new native-tables client-side catalog filter uses case-sensitive equality while the sibling cross-reference filter (same PR) is case-insensitive — Databricks identifiers are case-insensitive, so a case-mismatched catalog request can silently drop all rows.
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested change — the native-metadata bypass is cleanly factored (native_or_reshaped_stream) and the client-side filters that the native backend doesn't enforce are correctly re-applied. One medium concern: process_native_tables filters catalog case-sensitively while the sibling filter_cross_reference_by_parent (added in the same PR) is case-insensitive, which can silently drop table rows. Also a low note on the positional trust in normalize_native_metadata_batch.
There was a problem hiding this comment.
Verdict: 1 Medium
Solid, well-tested change that wires up native Thrift metadata results and the SHOW FUNCTIONS migration; headers, native-result bypass, and fallback filters are all covered by unit + wiremock tests. One medium concern: the new native tables catalog filter compares case-sensitively while its sibling cross-reference filter (added in the same commit) is case-insensitive, which can silently drop rows for case-mismatched catalog names.
dbd975a to
dee9218
Compare
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested change that wires up native Thrift metadata headers and honors is_native_metadata_result; the +1 ordinal, null-REMARKS→"", TABLE_TYPE default, and requested-vs-resolved FUNCTION_CAT all match the JDBC reference. One medium worth considering: native→JDBC column mapping is positional whereas JDBC maps by name, so a server-side column reorder could silently mis-assign values. Plus one low around empty-string session-catalog fallback.
| let columns = batch | ||
| .columns() | ||
| .iter() | ||
| .zip(schema.fields()) |
There was a problem hiding this comment.
🟡 Medium — normalize_native_metadata_batch maps native columns to the public JDBC schema positionally: it zips batch.columns() with schema.fields() in order and, after a column-count check, casts/normalizes each column purely by index (the name-based match field.name() only selects which value normalization to apply, not which source column to read). This assumes the server's Thrift-native result already arrives in the exact canonical column order of GET_*_SCHEMA.
The JDBC reference driver deliberately does not rely on ordering — copyThriftNativeMetadataRows resolves each target column by name (resultSet.getObject(mappedColumn.getResultSetColumnName())). If the native backend ever returns the canonical columns in a different order (or an unexpected extra/fewer column that still matches the count), the positional approach silently mis-assigns values rather than failing — many metadata columns are Utf8, so the type cast guard won't catch a reorder among string columns (e.g. TABLE_SCHEM vs TABLE_NAME). Consider matching JDBC by resolving source columns by name, or at minimum assert the native column names equal the expected schema names before trusting positional order.
| } | ||
| } | ||
|
|
||
| fn session_catalog_or_hive_metastore(&self) -> &str { |
There was a problem hiding this comment.
🔵 Low — session_catalog_or_hive_metastore only falls back to hive_metastore when the session catalog is None; a configured empty-string catalog (Some("")) is returned verbatim. In the list_functions null-catalog path that would build SHOW FUNCTIONS IN CATALOG ``` (empty identifier) rather than falling back. The JDBC reference treats null/empty currentCatalog uniformly before falling back. Low likelihood in practice, but treating Some("")the same asNonehere (fallback tohive_metastore`) would be more robust.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — solid, well-tested change that wires SEA metadata operation/native-result headers and honors is_native_metadata_result to bypass reshaping while keeping legacy fallback and client-side filters. Escaping (escape_show_pattern now applies both wildcard conversion and SQL-string escaping), catalog resolution (query_current_catalog with session/hive fallback), and the Int32→Int16 / null→empty / 0→1-based ordinal normalizations are all covered by unit + wiremock tests. One low-severity note on the classic single-column SHOW FUNCTIONS path inline.
| utf8_column(batch, "function")? | ||
| }; | ||
| let remarks = utf8_column(batch, "remarks")?; | ||
| let function_type = int16_column(batch, "functionType")?; |
There was a problem hiding this comment.
🔵 Low — Behavior change for the classic single-column SHOW FUNCTIONS shape: FUNCTION_TYPE is now derived from a functionType column that the classic shape does not carry, so int16_column returns an all-null Int16 array (falls into the None => branch that yields nulls). Previously reshape_functions hard-coded FUNCTION_TYPE = functionNoTable (1) for every row. So when the server returns the legacy single-function-column result, getFunctions now reports FUNCTION_TYPE = NULL instead of 1. The new test reshape_functions_supports_classic_single_column_shape covers this shape but deliberately does not assert on FUNCTION_TYPE, so the change is unverified. If JDBC parity for the classic path expects functionNoTable/functionResultUnknown rather than NULL, consider defaulting the column when functionType is absent; otherwise a short assertion/comment documenting the intended NULL would lock in the contract.
b79ea5a to
f8f5e35
Compare
There was a problem hiding this comment.
Verdict: 2 Low
Looks good — a well-structured, thoroughly-tested change (unit + wiremock coverage for every native operation and both functions fallback paths). The SQL-escaping refactor (jdbc_pattern_to_hive now wildcard-only, escape_show_pattern applying SQL-literal escaping) is correct and injection-safe, and the new client-side parent filter for cross-reference is a genuine JDBC-parity improvement applied to both paths. Two low-severity notes: the native-batch normalizer trusts column order (count-only guard, positional zip) which could silently mis-map on a contract drift, and FUNCTION_TYPE can now be NULL for the classic SHOW shape where it was previously a defined constant.
Other findings
- 🔵 Low —
normalize_native_metadata_batchvalidates only that the native batch's column count matches the JDBC schema, then zips columns positionally againstschema.fields()and casts each in place. It never checks column names. The safety of this rests entirely on the assumption stated in the doc comment ("Native metadata already has the canonical Thrift column order").
If a future server build (or an operation whose native result happens to have the same arity but a different column order) returns columns in an unexpected order, this will silently map data into the wrong JDBC column — and because every field is Utf8/Int32-ish, the arrow_cast::cast will often succeed rather than surfacing the mismatch. That's a silent-data-corruption failure mode gated on a server contract this PR is the first to depend on.
Consider validating field names positionally (or looking columns up by name) so a contract drift fails loudly instead of producing mis-attributed metadata rows. Not blocking given current server behavior, but cheap insurance for a cross-version contract.
- 🔵 Low —
reshape_functionspreviously emitted a constantfunctionNoTable(1) forFUNCTION_TYPEon every row. It now readsint16_column(batch, "functionType"), which — via the helper's missing-column branch — yields an all-nullFUNCTION_TYPEfor the classic single-columnSHOW FUNCTIONSshape (only afunctioncolumn present, exercised byreshape_functions_supports_classic_single_column_shape).
JDBC's getFunctions defines FUNCTION_TYPE as functionResultUnknown(0)/functionNoTable(1)/functionReturnsTable(2); null is not one of those values. Clients that expect a defined short here (rather than SQL NULL) will see a behavior change on older/classic backends. If the intent is to preserve a defined value when the server omits functionType, defaulting the missing case to 0 (functionResultUnknown) would be closer to the JDBC contract than null. Low-confidence / minor parity note — the modern SHOW result supplies functionType, so this only affects the classic fallback shape.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — well-scoped hardening of the native metadata path plus solid wiremock/unit coverage. The classic single-column SHOW FUNCTIONS fallback is safe (missing columns synthesize nulls via utf8_column/int16_column), the FUNCTION_NAME nullability relaxation is justified inline, and the zero→one-based ORDINAL_POSITION increment uses checked_add(1) with overflow handling and is covered by both native and legacy tests. One low-confidence note left inline about how the fully-qualified name lands in FUNCTION_NAME in the classic shape.
| let function_name = if column_index(batch.schema_ref(), "functionName").is_some() { | ||
| utf8_column(batch, "functionName")? | ||
| } else { | ||
| // Classic SHOW FUNCTIONS exposes a single column named `function`. |
There was a problem hiding this comment.
🔵 Low — Classic single-column SHOW FUNCTIONS fallback places the function column value directly into FUNCTION_NAME. Per the accompanying test, that column carries the fully-qualified name (e.g. system.builtin.abs) while FUNCTION_SCHEM/FUNCTION_CAT stay null (the namespace column is absent in this shape). JDBC/Thrift getFunctions normally splits catalog/schema/name across FUNCTION_CAT/FUNCTION_SCHEM/FUNCTION_NAME, so consumers filtering or joining on the unqualified name may not match. This is the fallback path only and the behavior is deliberately encoded by the test, so it's likely acceptable — but worth confirming it matches how the reference drivers surface the classic shape.
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — the classic single-column SHOW FUNCTIONS fallback and the ORDINAL_POSITION/catalog-override logic are correct (null-safe helpers, checked_add overflow guard, null-preserving branches) and the new wiremock/unit coverage exercises them properly. One low, non-blocking note about the classic path leaving FUNCTION_NAME as a fully-qualified name.
| utf8_column(batch, "functionName")? | ||
| } else { | ||
| // Classic SHOW FUNCTIONS exposes a single column named `function`. | ||
| utf8_column(batch, "function")? |
There was a problem hiding this comment.
🔵 Low — The classic-shape fallback maps the single function column straight into FUNCTION_NAME while leaving FUNCTION_SCHEM/FUNCTION_CAT null. Classic SHOW FUNCTIONS typically returns fully-qualified names (e.g. system.builtin.abs, as your own test fixture shows), so FUNCTION_NAME ends up carrying the catalog/schema-qualified string rather than the bare function name that JDBC's getFunctions contract expects in that column. This is a rarely-hit legacy path and the row is preserved rather than discarded (the actual goal of this PR), so it's non-blocking — but consumers filtering/joining on FUNCTION_NAME may see qualified values here. Worth a comment noting the intentional non-decomposition, or a follow-up to split the qualified name.
Final PR in the native metadata stack; depends on #355.
Stack: #353 → #354 → #355 → #336 (this).
Support the classic single-column SHOW FUNCTIONS fallback and add public-API native-result/header coverage for catalogs, schemas, both table routes, columns, keys, and functions.
The full stack produces the same source tree previously reviewed in #336; only the history and review boundaries changed.
Testing:
cargo +stable fmt --all,cargo clippy --all-targets -- -D warnings,cargo test.