Repository navigation
fix(metadata): align native Thrift metadata with JDBC - #354
vuanhphung wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.
286f67a to
098bfae
Compare
0a42c4b to
605bf96
Compare
098bfae to
7157f29
Compare
605bf96 to
2cf732c
Compare
7157f29 to
ace712d
Compare
2cf732c to
25bdb3d
Compare
There was a problem hiding this comment.
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.
25bdb3d to
fe0cd3e
Compare
fe0cd3e to
277b1fe
Compare
There was a problem hiding this comment.
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.
| // 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")?; |
There was a problem hiding this comment.
🟡 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>
277b1fe to
879e356
Compare
There was a problem hiding this comment.
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).
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
🔵 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.
Native Thrift metadata already uses JDBC column order, but the kernel mixed native batches with legacy
SHOWreshaping and trusted backend filtering, Arrow types, and values too closely.manifest.is_native_metadata_resultand enter legacySHOWreshapers, which expect different column names.maindropped rows returned asMAIN. Backend catalog/type/foreign-key parent narrowing was also not reliable enough to be the only filter.FUNCTION_TYPE: Int32, for example, failed because JDBC exposes it asInt16.TABLE_TYPEvalues could error or be filtered out; null remarks remained null.TABLE, and missing remarks become empty strings, matching the intended JDBC behavior.getFunctions(None, ...)could return null or differentFUNCTION_CATvalues on native and fallback paths. IfCURRENT_CATALOG()failed, the fallback immediately selectedhive_metastoreeven when the session had a configured catalog.hive_metastore. Both native and fallback rows report that same resolved catalog.SHOW FUNCTIONSwildcards first, then SQL-escaped exactly once.SHOW FUNCTIONSshapefunctionName; classic runtimes returning onefunctioncolumn failed the entire metadata call.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, andcargo test.