Repository navigation
feat(c-abi): expose procedure / function metadata as JDBC-canonical results - #237
Conversation
…esults ## What Adds three C ABI metadata functions and the JDBC-canonical reshaping behind them, making the kernel the single source of truth for procedure and function metadata (previously the ODBC driver hand-rolled its own information_schema queries for these): - `kernel_metadata_procedures` → JDBC `getProcedures` - `kernel_metadata_functions` → JDBC `getFunctions` - `kernel_metadata_procedure_columns` → JDBC `getProcedureColumns` ## Details - `SqlCommandBuilder::build_get_procedure_columns`: queries `information_schema.parameters` JOINed to `information_schema.routines` filtered to `routine_type = 'PROCEDURE'`, so function arguments are excluded (matching JDBC getProcedureColumns). Reuses the existing `escape_sql_string` / `resolve_catalog_prefix` helpers. - `thrift_shape`: new `GET_PROCEDURES_SCHEMA` (9 col), `GET_FUNCTIONS_SCHEMA` (6 col), `GET_PROCEDURE_COLUMNS_SCHEMA` (20 col) matching `java.sql.DatabaseMetaData`, plus `reshape_procedures` / `reshape_functions` / `reshape_procedure_columns`. This fills the procedures/functions reshape the module previously deferred, so those results are now JDBC-canonical like tables/columns/keys. `DATA_TYPE` reuses `databricks_type_to_xdbc` (the same per-row mapper getColumns uses); `COLUMN_TYPE` is derived from `parameter_mode` / `is_result`. - `Metadata::procedures` / `functions` now route through their reshape (they previously passed the raw server shape through); new `Metadata::procedure_columns`. New `Transport::list_procedure_columns` (SEA impl + test mocks). ## Why The ODBC driver has been reimplementing these information_schema queries driver-side; exposing them here lets ODBC (and the other kernel-backed drivers) share one implementation. ODBC will rewire onto these in a follow-up once this lands and the kernel pin is bumped. ## Testing - New builder unit tests (JOIN, PROCEDURE filter, LIKE/`=` escaping, catalog resolution) and reshape schema/mapping tests. - `cargo fmt`, `cargo clippy --all-targets -- -D warnings` clean. - `cargo test`: 886 passed, 58 ignored. - C ABI header syntax-checked as C and C++. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
…cedure_columns The v0 E2E surface test `functions_returns_information_schema_routine_columns` asserted the raw information_schema column names (`routine_catalog`, …). Now that `Metadata::functions` routes through `reshape_functions`, the result is the JDBC `getFunctions` column set — update the assertion accordingly (renamed to `functions_returns_jdbc_columns`, matching the sibling list_columns / keys tests). Also add sibling E2E coverage for the two newly-reshaped surfaces: `procedures_returns_jdbc_columns` and `procedure_columns_returns_jdbc_columns`, asserting the JDBC getProcedures / getProcedureColumns column sets. Verified live: all 12 v0_metadata_e2e --ignored tests pass. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
There was a problem hiding this comment.
Verdict: 2 Low
Solid, well-tested addition — the SQL builder, reshapes, FFI wiring, and error handling all mirror the existing getColumns/primaryKeys patterns, and every Transport impl (real + mocks) got the new method. Two low-severity parity/robustness notes below; nothing blocking.
| GET_FUNCTIONS_SCHEMA.clone(), | ||
| vec![ | ||
| function_cat, | ||
| function_schem, |
There was a problem hiding this comment.
🔵 Low — FUNCTION_TYPE is hard-coded to functionNoTable (1) for every function. Databricks supports table-valued functions (TVFs), for which JDBC getFunctions would report functionReturnsTable (2). Because build_get_functions only selects routine_catalog, routine_schema, routine_name, comment, specific_name, the reshape has no column to distinguish scalar from table functions, so all rows are reported as scalar. This is a known-limitation parity gap rather than a crash; if TVF fidelity matters, information_schema.routines exposes columns (e.g. data_type being NULL for table functions) that could drive the distinction — but that would require selecting them in the builder. Worth a comment noting the limitation at minimum.
| /// | ||
| /// `FUNCTION_TYPE` is constant `functionNoTable` (1) — Databricks functions | ||
| /// are scalar / return a value, not a table. (JDBC: `functionResultUnknown`=0, | ||
| /// `functionNoTable`=1, `functionReturnsTable`=2.) |
There was a problem hiding this comment.
🔵 Low — GET_PROCEDURE_COLUMNS_SCHEMA declares COLUMN_NAME and TYPE_NAME as non-nullable (Utf8, false), but reshape_procedure_columns feeds them directly from information_schema.parameters.parameter_name / data_type via utf8_column. Unlike SHOW COLUMNS (the source for reshape_columns, which is guaranteed non-null), information_schema.parameters can carry a NULL parameter_name for certain rows. If any row has a null there, RecordBatch::try_new fails the non-nullable check and the whole call returns a data_loss error instead of a result with a null cell — a harder failure than JDBC's null-tolerant contract for these columns. The routine_type = 'PROCEDURE' JOIN filters out the classic null-parameter-name case (function result columns), so this is low-probability, but marking the fields nullable (matching JDBC) would be more robust.
…ation_schema `information_schema.parameters.numeric_precision_radix` is inconsistent for integer parameters — it reports 2 for some INT parameters and NULL for others. Passing it through verbatim would make RADIX nondeterministic across otherwise identical procedures. Derive RADIX from the parameter's type instead, matching JDBC getProcedureColumns / the reference driver: 10 for exact decimals (DECIMAL/DEC/NUMERIC), 2 for the approximate types (FLOAT/REAL/DOUBLE), and NULL otherwise (integers included). PRECISION and SCALE still pass through. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
There was a problem hiding this comment.
Verdict: 1 High · 1 Low
Solid, well-tested addition that fills the deferred procedures/functions reshape gap and wires three C ABI exports. One correctness concern worth addressing before merge: the new GET_PROCEDURE_COLUMNS_SCHEMA declares source-backed string columns non-nullable, diverging from the file's own defensive convention (F1). Plus one minor dead-column note (F2).
| Field::new("PROCEDURE_CAT", DataType::Utf8, true), | ||
| Field::new("PROCEDURE_SCHEM", DataType::Utf8, true), | ||
| Field::new("PROCEDURE_NAME", DataType::Utf8, false), | ||
| Field::new("COLUMN_NAME", DataType::Utf8, false), |
There was a problem hiding this comment.
🟠 High — GET_PROCEDURE_COLUMNS_SCHEMA declares COLUMN_NAME (line 267) and TYPE_NAME (line 270) as non-nullable (false), and reshape_procedure_columns populates them directly from the raw information_schema.parameters columns parameter_name and data_type via utf8_column(...) / type_name_arr — passing source nulls straight through.
information_schema.parameters.parameter_name is nullable by the SQL standard: the return-value row (is_result = 'YES', which this reshape explicitly maps to procedureColumnReturn) and any unnamed/positional parameter carry a NULL name. When such a row is present, RecordBatch::try_new fails on the non-nullable-field-with-nulls violation, so the whole reshape_procedure_columns call returns a data_loss error and the metadata call fails.
This is exactly the failure mode the sibling schemas in this same file guard against: GET_COLUMNS_SCHEMA (line 148) and GET_PRIMARY_KEYS_SCHEMA (line 184) both declare COLUMN_NAME nullable with the comment "JDBC spec says non-null, but declare nullable so the reshape doesn't fail on those rows." The new schema breaks that established convention.
The unit test masks it: server_parameter_rows() gives the is_result='YES' return row a non-null parameter_name of "r", so the null path is never exercised. Recommend declaring COLUMN_NAME and TYPE_NAME nullable (matching the sibling schemas) and adding a fixture row with a NULL parameter_name to lock in the behavior.
| /// `routine_type = 'PROCEDURE'` to exclude function arguments — matching | ||
| /// `java.sql.DatabaseMetaData.getProcedureColumns`, which is procedures-only. | ||
| /// | ||
| /// Catalog resolution matches [`SqlCommandBuilder::build_get_procedures`]: |
There was a problem hiding this comment.
🔵 Low — build_get_procedure_columns selects p.numeric_precision_radix in the projection, but reshape_procedure_columns never reads it (RADIX is derived from the type name instead, as the reshape comment explains). The column is fetched over the wire and discarded. Minor: drop it from the SELECT list to avoid a dead column, or add a note in the builder that it is intentionally requested-but-unused for symmetry.
…s, drop dead column Addresses peco-review-bot findings on PR #237: - F1 (High): GET_PROCEDURE_COLUMNS_SCHEMA declared COLUMN_NAME and TYPE_NAME non-nullable, but reshape_procedure_columns feeds them straight from information_schema.parameters.parameter_name / data_type. The return-value row (is_result='YES') and unnamed/positional params carry a NULL parameter_name, which would fail RecordBatch::try_new (data_loss) and drop the whole result. Declare both nullable, matching the defensive convention of the sibling GET_COLUMNS_SCHEMA / GET_PRIMARY_KEYS_SCHEMA. Added a NULL-parameter_name return-value fixture row to lock in the behavior. - F2 (Low): build_get_procedure_columns selected p.numeric_precision_radix but reshape_procedure_columns derives RADIX from the type name and never reads it. Dropped the dead column from the SELECT. - Noted the FUNCTION_TYPE=functionNoTable known-limitation for table-valued functions (the builder selects no column that distinguishes scalar from TVF). cargo test / fmt / clippy --all-targets -D warnings all clean. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
| /// `PRECISION`, `LENGTH`, `NULLABLE`, `SQL_DATA_TYPE`, | ||
| /// `SQL_DATETIME_SUB`, `CHAR_OCTET_LENGTH`, and `ORDINAL_POSITION` are | ||
| /// `INTEGER` (Int32), per the JDBC spec. `LENGTH`, `SQL_DATA_TYPE`, | ||
| /// `SQL_DATETIME_SUB`, and `CHAR_OCTET_LENGTH` have no |
There was a problem hiding this comment.
🔵 Low — The GET_PROCEDURE_COLUMNS_SCHEMA doc comment lists CHAR_OCTET_LENGTH among the columns that "have no information_schema.parameters source and are emitted as null." That's incorrect: the SQL builder selects p.character_octet_length (sql.rs:420) and reshape_procedure_columns passes it through via int32_column(batch, "character_octet_length") at line 963 (placed in the CHAR_OCTET_LENGTH slot, not null_int32). The more-detailed reshape doc at line 881 correctly says CHAR_OCTET_LENGTH passes through, so this schema-level comment is self-contradictory. Drop CHAR_OCTET_LENGTH from the "emitted as null" list here (the genuinely-null columns are LENGTH, SQL_DATA_TYPE, SQL_DATETIME_SUB).
| Field::new("SQL_DATA_TYPE", DataType::Int32, true), | ||
| Field::new("SQL_DATETIME_SUB", DataType::Int32, true), | ||
| Field::new("CHAR_OCTET_LENGTH", DataType::Int32, true), | ||
| Field::new("ORDINAL_POSITION", DataType::Int32, false), |
There was a problem hiding this comment.
🔵 Low — ORDINAL_POSITION is declared non-nullable (Field::new("ORDINAL_POSITION", DataType::Int32, false)) yet is a raw passthrough from information_schema.parameters.ordinal_position via int32_column(batch, "ordinal_position") (line 964). This is asymmetric with the sibling passthrough columns PRECISION/SCALE/RADIX/CHAR_OCTET_LENGTH, which were all declared nullable, and with the explicit defensive reasoning applied to COLUMN_NAME (lines 267-273): a NULL in a non-nullable column fails RecordBatch::try_new with a data_loss error and drops the entire result. If Databricks ever reports a NULL ordinal_position (e.g. for the return-value row), the whole procedure-columns result is lost rather than degrading one cell. Consider declaring ORDINAL_POSITION nullable for the same defensiveness, or synthesizing a non-null fallback. The existing test fixture always supplies a non-null ordinal_position, so this path is currently unexercised.
What
Adds three C ABI metadata functions and the JDBC-canonical reshaping behind them, making the kernel the single source of truth for procedure and function metadata:
kernel_metadata_procedures→ JDBCgetProcedureskernel_metadata_functions→ JDBCgetFunctionskernel_metadata_procedure_columns→ JDBCgetProcedureColumnsWhy
The OSS ODBC driver currently reimplements these
information_schemaqueries driver-side (SQLProceduresruns its owninformation_schema.routinesquery;SQLProcedureColumnswas recently prototyped the same way). The kernel already hadbuild_get_procedures/build_get_functionsbut never exposed them over the C ABI, and itsthrift_shapemodule explicitly deferred the procedures/functions reshape. This change fills that gap so ODBC — and the other kernel-backed drivers — can share one implementation instead of each hand-rolling the query and column mapping.The ODBC driver will rewire
GetProcedures/GetProcedureColumnsonto these functions in a follow-up, once this lands and the ODBC kernel pin is bumped.Details
src/metadata/sql.rs):build_get_procedure_columnsqueriesinformation_schema.parametersJOINed toinformation_schema.routinesfiltered toroutine_type = 'PROCEDURE', so function arguments are excluded (matching JDBCgetProcedureColumns). Reuses the existingescape_sql_string/resolve_catalog_prefixhelpers.src/metadata/thrift_shape.rs): newGET_PROCEDURES_SCHEMA(9 col),GET_FUNCTIONS_SCHEMA(6 col),GET_PROCEDURE_COLUMNS_SCHEMA(20 col) matchingjava.sql.DatabaseMetaData, plusreshape_procedures/reshape_functions/reshape_procedure_columns.DATA_TYPEreusesdatabricks_type_to_xdbc(the same per-row mappergetColumnsuses);COLUMN_TYPEis derived fromparameter_mode/is_result(IN=1, INOUT=2, OUT=4, return=5).metadata_v0.rs,transport.rs,sea.rs, test mocks):Metadata::procedures/functionsnow route through their reshape (they previously passed the raw server shape through — the deferred gap); newMetadata::procedure_columnsandTransport::list_procedure_columns.src/c_abi/metadata.rs,include/databricks_kernel.h): the three new exports, replacing the prior "wire these later" placeholder.Testing
=escaping, catalog resolution) and reshape schema/column-mapping tests.cargo fmt+cargo clippy --all-targets -- -D warningsclean.cargo test: 886 passed, 58 ignored.This pull request and its description were written by Isaac.