Skip to content

fix(metadata): align native Thrift metadata with JDBC - #354

Closed
vuanhphung wants to merge 4 commits into
mainfrom
feat/native-thrift-metadata-functions
Closed

vuanhphung wants to merge 4 commits into
mainfrom
feat/native-thrift-metadata-functions

Conversation

@vuanhphung

@vuanhphung vuanhphung commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Native Thrift metadata already uses JDBC column order, but the kernel mixed native batches with legacy SHOW reshaping and trusted backend filtering, Arrow types, and values too closely.

Area Before After
Native-result routing Some metadata results could lose or ignore manifest.is_native_metadata_result and enter legacy SHOW reshapers, which expect different column names. The marker is retained through result readers. Native catalogs, schemas, tables, columns, keys, and functions use the canonical Thrift column order; only non-native results use legacy reshaping.
Catalog and parent filtering Native table catalog filtering used case-sensitive equality, so a request for main dropped rows returned as MAIN. Backend catalog/type/foreign-key parent narrowing was also not reliable enough to be the only filter. Catalog, table-type, and foreign-key parent filters are applied client-side with case-insensitive identifier comparisons.
Native Arrow schemas Reattaching the public schema required exact physical types. A native FUNCTION_TYPE: Int32, for example, failed because JDBC exposes it as Int16. Native batches validate column count and cast compatible physical types to the stable public JDBC schema; incompatible values still return a data-loss error.
Native table/column values Column ordinals remained zero-based; null or empty TABLE_TYPE values could error or be filtered out; null remarks remained null. Ordinals become one-based, missing table types default to TABLE, and missing remarks become empty strings, matching the intended JDBC behavior.
Function catalog resolution getFunctions(None, ...) could return null or different FUNCTION_CAT values on native and fallback paths. If CURRENT_CATALOG() failed, the fallback immediately selected hive_metastore even when the session had a configured catalog. The catalog resolves in order from the explicit argument, current catalog, configured session catalog, then hive_metastore. Both native and fallback rows report that same resolved catalog.
Function-pattern SQL JDBC wildcard conversion and SQL-literal escaping were coupled, so quoted schema/function patterns could produce malformed or unsafe SQL. Patterns are converted to SHOW FUNCTIONS wildcards first, then SQL-escaped exactly once.
Legacy SHOW FUNCTIONS shape Fallback reshaping assumed the newer multi-column result with functionName; classic runtimes returning one function column failed the entire metadata call. Fallback reshaping accepts both result shapes and synthesizes absent optional JDBC columns as null.

Public wiremock coverage now exercises native headers and results for catalogs, schemas, exact and wildcard tables, columns, primary keys, foreign keys, and functions, plus explicit/current/session function-catalog fallbacks.

Scope: this PR only normalizes the values listed above; it does not add broader JDBC synthesis for column size, precision, scale, or radix fields.

Testing: cargo +stable fmt --all -- --check, cargo clippy --all-targets -- -D warnings, and 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 that moves getFunctions onto the catalog-aware SHOW FUNCTIONS IN CATALOG path with a hive_metastore fallback, matching the JDBC driver's catalog resolution and column mapping (verified against DatabricksMetadataQueryClient.listFunctions / MetadataResultSetBuilder / CommandBuilder). No correctness or resource-safety issues found in query_current_catalog or the reshape. One medium concern: the native normalization requires FUNCTION_TYPE to be exactly Int16 with no cast, which the fallback path evidence suggests the server may not honor; plus one low SQL-parity nit.

Comment thread src/metadata_v0.rs Resolved
Comment thread src/metadata/sql.rs Resolved
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-routing branch from 286f67a to 098bfae Compare September 23, 2026 00:36
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-functions branch from 0a42c4b to 605bf96 Compare September 23, 2026 00:36
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-routing branch from 098bfae to 7157f29 Compare September 23, 2026 00:40
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-functions branch from 605bf96 to 2cf732c Compare September 23, 2026 00:40
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-routing branch from 7157f29 to ace712d Compare September 23, 2026 00:45
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-functions branch from 2cf732c to 25bdb3d Compare September 23, 2026 00:45

@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, JDBC-aligned rework of getFunctions onto the catalog-aware SHOW FUNCTIONS path; the native path and its wiremock coverage look correct. One medium concern: the non-native reshape fallback reads FUNCTION_CAT from a catalogName column that raw SHOW FUNCTIONS doesn't carry (JDBC injects the resolved catalog instead), so FUNCTION_CAT degrades to null on non-native servers — a path that also lacks test coverage. Plus one low note on an always-appended LIKE '*' clause.

Comment thread src/metadata/thrift_shape.rs Resolved
Comment thread src/metadata/sql.rs Resolved
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-functions branch from 25bdb3d to fe0cd3e Compare September 23, 2026 22:37
@vuanhphung
vuanhphung requested a review from a team as a code owner September 23, 2026 22:37
@vuanhphung
vuanhphung changed the base branch from feat/native-thrift-metadata-routing to main September 23, 2026 22:38
@vuanhphung
vuanhphung force-pushed the feat/native-thrift-metadata-functions branch from fe0cd3e to 277b1fe Compare September 23, 2026 22:40

@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 alignment of GetFunctions with JDBC: the SHOW FUNCTIONS IN CATALOG SQL, current-catalog resolution with hive_metastore fallback, native column names, and Int32→Int16 functionType narrowing all match the reference driver. One medium concern: the non-native fallback reshape_functions reads FUNCTION_CAT from a catalogName column that the raw SHOW FUNCTIONS result doesn't emit (JDBC synthesizes it from the resolved catalog), so that path yields a null catalog — and only the native path has wiremock coverage.

Comment thread src/metadata/thrift_shape.rs Outdated
// them apart. Known parity gap; distinguishing TVFs would require selecting
// additional information_schema.routines columns in the builder.
let function_type = Arc::new(Int16Array::from(vec![Some(1_i16); n])) as ArrayRef;
let function_cat = utf8_column(batch, "catalogName")?;

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 — On the non-native (fallback reshape) path, reshape_functions reads FUNCTION_CAT from a catalogName column of the raw SHOW FUNCTIONS result:

let function_cat = utf8_column(batch, "catalogName")?;

But the raw SHOW FUNCTIONS IN CATALOG … result does not contain a catalogName column — that is precisely why the JDBC driver (which this PR aims to match) synthesizes FUNCTION_CAT from the resolved catalog (row.add(catalog)), reading only namespace, functionName, remarks, functionType, and specificName from the server. utf8_column returns a synthesized all-null column when the name is absent (thrift_shape.rs:330), so on the fallback path FUNCTION_CAT comes out all-null, whereas JDBC fills it with the resolved catalog. This diverges from JDBC for exactly the case (older DBR / non-native metadata) the fallback exists to serve.

Compounding this, reshape_functions is not passed the resolved catalog, so it cannot fill FUNCTION_CAT correctly even if it wanted to — unlike the native path, which threads requested_catalog into normalize_native_functions_batch.

The unit test reshape_functions_produces_jdbc_get_functions_shape uses a hand-authored server_function_row() fixture that includes a catalogName column (thrift_shape.rs:2001-2024), so it does not exercise the real server shape and masks the gap. Consider (a) passing the resolved catalog into the fallback reshape and synthesizing FUNCTION_CAT from it like JDBC, and (b) adding a wiremock test that drives the non-native SHOW FUNCTIONS result (no catalogName column) end-to-end — currently only the native path has wiremock coverage.

Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
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 Medium · 1 Low

Solid, well-tested move from the information_schema.routines SELECT to the JDBC-aligned SHOW FUNCTIONS IN CATALOG path; the SQL builder, reshape, and Int32→Int16 narrowing all look correct. Two non-blocking concerns: (1) FUNCTION_CAT is filled differently by the native vs fallback path for a null-catalog request (medium — please confirm intent), and (2) the new hive_metastore catalog-resolution fallbacks are untested (low).

Comment thread src/metadata_v0.rs Resolved
Comment thread src/client/sea.rs Resolved
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
@vuanhphung vuanhphung changed the title fix(metadata): align GetFunctions with JDBC fix(metadata): align native Thrift metadata with JDBC Sep 24, 2026
@vuanhphung vuanhphung closed this Sep 24, 2026

@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 overall — the SHOW FUNCTIONS migration, two-step pattern escaping (jdbc_pattern_to_hive + escape_sql_string), classic single-column tolerance, Int32→Int16 narrowing, and null-catalog resolution all match JDBC and are well-covered by unit + wiremock tests. One low-severity parity note: the native path stamps FUNCTION_CAT with the resolved catalog whereas JDBC preserves the (possibly null) requested catalog for native results — worth confirming it's intentional.

Comment thread src/metadata_v0.rs
let normalized = normalize_native_metadata_batch(batch, GET_FUNCTIONS_SCHEMA.clone())?;
let mut columns = normalized.columns().to_vec();
columns[0] = Arc::new(StringArray::from(vec![
Some(resolved_catalog);

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 — For the native metadata path, this unconditionally stamps every row's FUNCTION_CAT with the resolved catalog. JDBC deliberately does not: listFunctions passes requestedCatalog (the original, possibly-null arg) to getFunctionsResult for native results, and only the resolved catalog for the SHOW path. Because native GetFunctions ignores catalog filtering and returns an empty FUNCTION_CAT (see the JDBC comment at DatabricksMetadataQueryClient.java:246 and MetadataResultSetBuilder.getFunctionsResult, which only overwrites when catalog != null), the returned functions may include builtin/cross-catalog entries that do not actually belong to the resolved current catalog. Labelling all of them with e.g. main (as the native_functions_no_filters_use_resolved_catalog wiremock test asserts) can mislabel those rows, diverging from JDBC for a PR whose stated goal is JDBC alignment. The SHOW/fallback path (reshape_functions using constant_utf8(resolved_catalog)) does match JDBC — the concern is native-only. If the divergence is intentional (filling the more-useful resolved catalog), consider documenting why it departs from JDBC here; otherwise mirror JDBC by preserving the requested catalog for native results.

This branch was previously deployed

1 inactive deployment
azure-prod — 17deba80 Deployed Sep 24, 2026 by vuanhphung via followup #1595
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.

1 participant