Repository navigation
feat(reader): comparator parity — re-land of #64 (intervals_as_string, empty-result schema, composite types, TIMESTAMP tz, metadata reshape, named params) - #72
Merged
Conversation
… + empty-result schema + composite + TIMESTAMP tz + getTables/getColumns metadata + named params) > ## Re-land of #64 > > PR #64 was filed as a stacked PR with base `docs/complex-types-json-stringify`. > That parent branch's content reached `main` via PR #36 (squash-merge) on > 2026-05-25 06:16Z. PR #64 then merged at 07:33Z — but **into the parent** > branch which by that point was effectively detached from `main`. The merge > commit (`fd2c576`) is not an ancestor of `origin/main`, so #64's content > never reached the public branch even though GitHub reports it as MERGED. > > This commit cherry-picks `fd2c576` onto `main` so the eight > comparator-parity fixes (most importantly: named-parameter binding, > required by released connector PR #803) actually land. > > Single conflict during cherry-pick: `src/reader/mod.rs` imports — `main` > requires `DataType`+`async_trait` (added by PR #26), the cherry-pick > branch didn't. Resolved by keeping `main`'s wider import set and dropping > the now-unused `DataType`. Verified: `cargo test --lib` → 436/436 pass, > `cargo test --test v0_execute_wiremock` → 11/11 pass. Eight comparator-parity fixes in the kernel's result-reader, metadata-reshape, and parameter-binding pipelines, surfaced by the python-comparator audit. pyarrow's Python bindings can't decode Arrow's `month_interval` (id 21) at all. Every kernel-backend `SELECT *` over a table with `INTERVAL YEAR TO MONTH` columns threw `ArrowNotImplementedError`. **32 / 88** comparator diffs. - `ResultConfig::intervals_as_string` (default `false`) + `PostProcessOptions::intervals_as_string`. When true, the post-processor stringifies `Interval(*)` / `Duration(*)` columns to `Utf8`. - Disjoint with the JSON-rewrite path; fused into one per-batch walk. Renames `build_json_batch` → `build_rewritten_batch`. - The Python connector ([PR sets it `true`. Exposes `complex_types_as_json` and `intervals_as_string` as kwargs on `Session(...)`. Merged into one `ResultConfig` so the toggles don't clobber each other. `extract_schema_from_manifest` was calling a local `map_databricks_type` that handled ~10 type names. DECIMAL, INTERVAL, VOID, ARRAY, MAP, STRUCT all fell through to `Utf8`. - Delete the duplicate. Route through the shared `metadata::type_mapping::databricks_type_to_arrow`. Pass `col.type_text` instead of `col.type_name` so precision/scale come through. - Parse composite type text via recursive descent: `ARRAY<INT>` → `List<Int32>`, `MAP<STRING,INT>` → `Map<Struct{key,value}>`, `STRUCT<x:INT,y:STRING>` → `Struct<...>`. Nested shapes (`ARRAY<ARRAY<INT>>`, `MAP<STRING,MAP<STRING,INT>>`, `STRUCT<a:ARRAY<INT>,b:MAP<STRING,INT>>`) parse correctly. Bad input falls back to `Utf8`. The TIMESTAMP arm was sharing a match case with TIMESTAMP_NTZ. Plain TIMESTAMP is logically TIMESTAMP_LTZ; the non-empty wire schema emits `Timestamp(Microsecond, Some("Etc/UTC"))`. - Split TIMESTAMP/TIMESTAMP_NTZ into separate arms. - TIMESTAMP and TIMESTAMP_LTZ → `Timestamp(Microsecond, Some("Etc/UTC"))` (matches wire path exactly). - TIMESTAMP_NTZ → `Timestamp(Microsecond, None)`. In `reshape_tables`, the `table_types` filter was treating `Some(&[])` identically to `None` ("no filter"). Thrift backend returns *zero rows* on an explicit empty array — the literal reading of "filter accepting nothing". JDBC Javadoc is silent on the empty case; this picks Thrift's reading for parity. - Remove the `if !types.is_empty()` guard so `Some(&[])` hits the filter path. - Existing test renamed (`..._passes_everything` → `..._returns_zero_rows`); new test locks the `None` path separately. `reshape_columns` (and `reshape_tables`) emitted Arrow nulls for REMARKS when the server didn't supply a comment. JDBC spec allows null, but the Thrift backend has historically returned `""` and consumers expect a `String`. - New `utf8_column_or_empty(batch, name)` helper that substitutes `""` for null entries. - Used for REMARKS in both `reshape_tables` and `reshape_columns`. Kernel returned `""` (JDBC's "unknown" sentinel) because the server omits the field. Databricks tables don't support auto-increment, so `"NO"` is the domain-correct answer. - Refactored `bool_string_to_yn` into a thin wrapper over `bool_string_to_yn_with_default(batch, name, default)`. Each callsite picks its null-fallback. - IS_NULLABLE keeps the `""` default (genuine unknown for computed columns / views). - IS_AUTO_INCREMENT uses `"NO"` default. Server-provided `"true"`/`"false"` still wins, so the kernel honours real identity columns if Databricks ever ships them. `StatementSpec.named_params` was rejected at execute time with "named parameter bindings are not supported in v0 — SEA wire format carries positional bindings only". That conclusion came from the kernel's local Rust `StatementParameter` struct, which only had `ordinal`. The canonical SEA proto (`sql_exec_api_service.proto`) defines: ```proto message StatementParameter { optional int32 ordinal = 1 [(visibility) = PUBLIC_UNDOCUMENTED]; optional string name = 2 [(databricks.openapi.field).openapi_required = true]; optional string value = 3; optional string type = 4; repeated StatementParameterValueArg args = 5; } ``` `name` is the documented public field; `ordinal` is `PUBLIC_UNDOCUMENTED` "for future extension to positional parameters". The kernel's local types were out of sync. - `StatementParameter` gains `name: Option<String>`; `ordinal` becomes `Option<i32>`. Both serialize with `skip_serializing_if = "Option::is_none"` so the JSON shape on the wire matches the proto: a positional param sends only `ordinal`, a named one sends only `name`. - `named_typed_value_to_sea_parameter(name, value)` helper mirrors the existing positional helper. - `Statement::execute` forwards `spec.named_params` via the new helper instead of rejecting. - PyO3 gains `Statement.bind_named_param(name, value_str, sql_type)` mirroring `bind_param`. Server side: live e2e against a real warehouse confirms named-only binding works. Mixed positional + named in one statement is rejected by the server with `INVALID_PARAMETER_MARKER_VALUE.MISSING_NAME` — bindings must be uniformly one or the other. The kernel surfaces this server-side rejection cleanly (covered by `mixed_positional_and_named_params_is_server_side_error`). | | Before any kernel work | After this PR + connector #803 | |---|---|---| | **match / diff (of 132 cases)** | 60 / 88 | **97 / 34 / 1 skipped** | | Bucket A (ArrowNotImplementedError) | 32 | **0** ✅ | | `decimal_column` precision/scale | 88 (connector) | **0** ✅ | | `decimal_column` type slot (empty) | 7 | **0** ✅ | | Complex-type slots (`ARRAY`/`MAP`/`STRUCT` in `fetchall_arrow`) | 12 | **0** ✅ | | `timestamp_column` tz slot | 1 | **0** ✅ | | `getTables(types=[])` rows | 8 | **0** ✅ | | `getColumns` IS_AUTO_INCREMENT cells | 5150 | **0** ✅ | | `getColumns` REMARKS cells | 5122 | **3796** (residual is real text differences, not null-vs-empty) | | Bucket B1 (named params) | 1 | **0** ✅ | | Fully-clean (config × suite) pairs | 12 / 30 | **18 / 30** | Remaining diffs cluster into documented buckets (METADATA `_` wildcards + system schemas as accepted divergences; empty-result nullability — fixable in a follow-up; Thrift backend per-row bugs to be fixed in `databricks-sql-python` separately) — see `~/docs/python-kernel/comparator-diff-tasklist.md`. - [x] `cargo test --lib` — **421/421 pass** (3 new tests on top of prior baseline: named StatementParameter JSON shape, named TypedValue helper, named Binary rejection) - [x] `cargo test --lib metadata::type_mapping` — 20/20 (12 existing + 8 new composite-type parser tests; TIMESTAMP test updated) - [x] `cargo test --lib metadata::thrift_shape` — 17/17 (13 existing + 4 new for `types=[]`, REMARKS null→`""`, IS_AUTO_INCREMENT default→`"NO"`, honors-server-true, no-when-column-missing) - [x] `cargo test --lib reader::tests` — 19/19 - [x] `cargo test --lib reader::post_processor` — 21/21 - [x] `cargo test --test v0_execute_wiremock` — 11/11 (`execute_rejects_named_params_in_v0` flipped to `execute_sends_named_params_in_wire_form`) - [x] `cargo test --test v0_execute_e2e -- --ignored` — live against the pecotesting warehouse. New: `select_with_named_params` passes, `mixed_positional_and_named_params_is_server_side_error` documents the server-side constraint. - [x] End-to-end via the python-comparator: numbers above; bucket B1 confirmed 1 → 0. Base: `docs/complex-types-json-stringify` (PR #36). That PR adds `ResultConfig::complex_types_as_json` and the post-processor framework; this PR adds the PyO3 binding for it, extends the post-processor with `intervals_as_string`, fixes the empty-result schema path, adds composite-type parsing + TIMESTAMP tz correctness, aligns `getTables` / `getColumns` reshaping with Thrift's behavior where the JDBC spec is ambiguous or the kernel was less informative, and adds named-parameter binding support. This pull request and its description were written by Isaac. Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
eric-wang-1990
added a commit
that referenced
this pull request
Aug 13, 2026
…ver2 #83) `reshape_tables` special-cased `Some(&[])` (explicit empty table_types slice) as match-ALL, equivalent to `None` — added in #201 (fix for #187) and relied on by #223's C-ABI cleanup. That premise was reversed by adbc-drivers/hiveserver2 #83: an empty type filter matches NOTHING (zero rows), matching databricks-jdbc's long-standing `listTables` short-circuit, and driver-test's METADATA-035 conformance test was flipped to expect match-none on 2026-08-06. The kernel driver landed the opposite behavior on 2026-08-10, so the live nightly (get_tables_empty_table_types_filter_matches_none, both normal and reyden legs) went red: the test demands 0 rows, the driver returned all rows. Realign the driver with the canonical (#83) contract: - thrift_shape.rs: drop the `Some([]) => reshaped` arm so an empty slice flows through `filter_tables_by_type`, whose `types.iter().any(..)` is false for every row → a correctly-typed empty batch. Only `None` now means match-all. Rewrote the inline + doc comments (they cited the reversed #72 reading). - thrift_shape.rs unit test: tables_empty_types_matches_all → tables_empty_types_matches_none (asserts 0 rows). - c_abi/metadata.rs: re-add the empty-CSV → `None` collapse that #223 removed. ODBC passes "" / whitespace / comma-only junk for "no type filter" (match-all); now that `Some(&[])` means match-none again on the Rust surface, the C-ABI boundary must collapse an empty parse back to `None` to preserve ODBC's empty→"all types" convention. Keeps #223's `split_table_types_csv` helper; restores the pre-#223 guard via `.filter(|t| !t.is_empty())`. The napi/pyo3 typed surfaces intentionally pass `Some(&[])` through (match-none), consistent with the Rust API. Validated: 766 lib unit tests pass; fmt + clippy clean; the live E2E get_tables_empty_table_types_filter_matches_none passes against a real warehouse (was red in the nightly). Reopens/supersedes #187 (its match-all premise is overturned by #83). Co-authored-by: Isaac
eric-wang-1990
added a commit
that referenced
this pull request
Aug 14, 2026
…ver2 #83) `reshape_tables` special-cased `Some(&[])` (explicit empty table_types slice) as match-ALL, equivalent to `None` — added in #201 (fix for #187) and relied on by #223's C-ABI cleanup. That premise was reversed by adbc-drivers/hiveserver2 #83: an empty type filter matches NOTHING (zero rows), matching databricks-jdbc's long-standing `listTables` short-circuit, and driver-test's METADATA-035 conformance test was flipped to expect match-none on 2026-08-06. The kernel driver landed the opposite behavior on 2026-08-10, so the live nightly (get_tables_empty_table_types_filter_matches_none, both normal and reyden legs) went red: the test demands 0 rows, the driver returned all rows. Realign the driver with the canonical (#83) contract: - thrift_shape.rs: drop the `Some([]) => reshaped` arm so an empty slice flows through `filter_tables_by_type`, whose `types.iter().any(..)` is false for every row → a correctly-typed empty batch. Only `None` now means match-all. Rewrote the inline + doc comments (they cited the reversed #72 reading). - thrift_shape.rs unit test: tables_empty_types_matches_all → tables_empty_types_matches_none (asserts 0 rows). - c_abi/metadata.rs: re-add the empty-CSV → `None` collapse that #223 removed. ODBC passes "" / whitespace / comma-only junk for "no type filter" (match-all); now that `Some(&[])` means match-none again on the Rust surface, the C-ABI boundary must collapse an empty parse back to `None` to preserve ODBC's empty→"all types" convention. Keeps #223's `split_table_types_csv` helper; restores the pre-#223 guard via `.filter(|t| !t.is_empty())`. The napi/pyo3 typed surfaces intentionally pass `Some(&[])` through (match-none), consistent with the Rust API. Validated: 766 lib unit tests pass; fmt + clippy clean; the live E2E get_tables_empty_table_types_filter_matches_none passes against a real warehouse (was red in the nightly). Reopens/supersedes #187 (its match-all premise is overturned by #83). Co-authored-by: Isaac Signed-off-by: eric-wang-1990 <e.wang@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-land of #64
PR #64 was filed as a stacked PR with base `docs/complex-types-json-stringify`. That parent branch's content reached `main` via #36 (squash-merge) on 2026-05-25 06:16Z. PR #64 then merged at 07:33Z — but into the parent branch, which by that point was effectively detached from `main`. The merge commit (`fd2c576`) is not an ancestor of `origin/main`, so #64's content never reached the public branch even though GitHub reports it as `MERGED`.
This is verifiable:
```
$ git merge-base --is-ancestor fd2c576 origin/main && echo on || echo off
off
```
This PR cherry-picks `fd2c576` onto `main` so the eight comparator-parity fixes (most importantly: named-parameter binding, required by released connector PR #803 in `databricks-sql-python`) actually land. Connector #803 is currently broken in the wild because it calls `Statement.bind_named_param` which doesn't exist on the public kernel.
Cherry-pick details
Single content conflict: `src/reader/mod.rs` imports. `main` requires `DataType` + `async_trait` (added by #26 after #64 was filed); the cherry-pick branch didn't. Resolved by keeping `main`'s wider import set and dropping the now-unused `DataType` (the cherry-picked content uses other identifiers, not `DataType`, at this site).
Verification
Original #64 description (preserved below for review continuity)
Eight comparator-parity fixes in the kernel's result-reader, metadata-reshape, and parameter-binding pipelines, surfaced by the python-comparator audit:
Full original PR description and comparator outcome table: #64
This pull request and its description were written by Isaac.