Skip to content

feat(c-abi): expose procedure / function metadata as JDBC-canonical results - #237

Merged
vikrantpuppala merged 4 commits into
mainfrom
feat/procedure-metadata-c-abi
Aug 11, 2026
Merged

vikrantpuppala merged 4 commits into
mainfrom
feat/procedure-metadata-c-abi

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

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 → JDBC getProcedures
  • kernel_metadata_functions → JDBC getFunctions
  • kernel_metadata_procedure_columns → JDBC getProcedureColumns

Why

The OSS ODBC driver currently reimplements these information_schema queries driver-side (SQLProcedures runs its own information_schema.routines query; SQLProcedureColumns was recently prototyped the same way). The kernel already had build_get_procedures / build_get_functions but never exposed them over the C ABI, and its thrift_shape module 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 / GetProcedureColumns onto these functions in a follow-up, once this lands and the ODBC kernel pin is bumped.

Details

  • SQL builder (src/metadata/sql.rs): 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.
  • Reshapes (src/metadata/thrift_shape.rs): 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. DATA_TYPE reuses databricks_type_to_xdbc (the same per-row mapper getColumns uses); COLUMN_TYPE is derived from parameter_mode / is_result (IN=1, INOUT=2, OUT=4, return=5).
  • Client wiring (metadata_v0.rs, transport.rs, sea.rs, test mocks): Metadata::procedures / functions now route through their reshape (they previously passed the raw server shape through — the deferred gap); new Metadata::procedure_columns and Transport::list_procedure_columns.
  • C ABI (src/c_abi/metadata.rs, include/databricks_kernel.h): the three new exports, replacing the prior "wire these later" placeholder.

Testing

  • New builder unit tests (JOIN, PROCEDURE filter, LIKE/= escaping, catalog resolution) and reshape schema/column-mapping tests.
  • cargo fmt + cargo clippy --all-targets -- -D warnings clean.
  • cargo test: 886 passed, 58 ignored.
  • C ABI header syntax-checked as both C and C++.

This pull request and its description were written by Isaac.

…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>

@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

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,

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 — 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.)

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

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 11, 2026
@vikrantpuppala
vikrantpuppala removed this pull request from the merge queue due to a manual request Aug 11, 2026
…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>

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

Comment thread src/metadata/thrift_shape.rs Outdated
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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/metadata/sql.rs
/// `routine_type = 'PROCEDURE'` to exclude function arguments — matching
/// `java.sql.DatabaseMetaData.getProcedureColumns`, which is procedures-only.
///
/// Catalog resolution matches [`SqlCommandBuilder::build_get_procedures`]:

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 — 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>

@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

Solid, well-tested addition — the SQL builder, reshapes, client wiring, and C ABI all hang together and carry good unit + e2e coverage. Two low-severity doc/robustness nits around GET_PROCEDURE_COLUMNS_SCHEMA noted inline; nothing blocking.

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

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 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),

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

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 11, 2026
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 11, 2026
@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 11, 2026
Merged via the queue into main with commit 00b16c3 Aug 11, 2026
22 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 9ff32479 Deployed Aug 11, 2026 by oss-reviewer-bot[bot] via followup #259
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