Skip to content

fix(metadata): harden native metadata fallback coverage - #336

Closed
vuanhphung wants to merge 1 commit into
fix/native-thrift-metadata-normalizationfrom
feat/native-thrift-metadata
Closed

vuanhphung wants to merge 1 commit into
fix/native-thrift-metadata-normalizationfrom
feat/native-thrift-metadata

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@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.

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.

Comment thread src/metadata/thrift_shape.rs Resolved
Comment thread src/metadata_v0.rs Resolved

@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.

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.

Comment thread src/metadata/thrift_shape.rs Resolved

@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.

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.

Comment thread src/metadata/thrift_shape.rs Resolved
Comment thread src/metadata_v0.rs Resolved

@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.

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.

Comment thread src/metadata/thrift_shape.rs Resolved

@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.

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.

Comment thread src/metadata_v0.rs
let columns = batch
.columns()
.iter()
.zip(schema.fields())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment thread src/client/sea.rs
}
}

fn session_catalog_or_hive_metastore(&self) -> &str {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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.

@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.

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")?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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.

@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata branch from b79ea5a to f8f5e35 Compare September 22, 2026 23:22
@vuanhphung vuanhphung changed the title feat(metadata): request native Thrift metadata results fix(metadata): harden native metadata fallback coverage Sep 22, 2026
@vuanhphung
vuanhphung changed the base branch from main to fix/native-thrift-metadata-normalization September 22, 2026 23:25

@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.

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_batch validates only that the native batch's column count matches the JDBC schema, then zips columns positionally against schema.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_functions previously emitted a constant functionNoTable (1) for FUNCTION_TYPE on every row. It now reads int16_column(batch, "functionType"), which — via the helper's missing-column branch — yields an all-null FUNCTION_TYPE for the classic single-column SHOW FUNCTIONS shape (only a function column present, exercised by reshape_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.

@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.

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`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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.

@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.

Signed-off-by: Vu Anh Phung <vu.phung@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.

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")?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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.

This branch was previously deployed

1 inactive deployment
azure-prod — e89a072c Deployed Sep 24, 2026 by oss-reviewer-bot[bot] via followup #1594
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant