Skip to content

fix(reader): surface untyped NULL (VOID) columns as STRING, matching Thrift - #235

Merged
vikrantpuppala merged 2 commits into
mainfrom
fix/203-untyped-null-string-type
Aug 10, 2026
Merged

vikrantpuppala merged 2 commits into
mainfrom
fix/203-untyped-null-string-type

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Summary

An untyped NULL column (SELECT NULL, VOID) reported Arrow DataType::Null while a CAST(NULL AS STRING) sibling in the same query reported Utf8 — a self-inconsistent result set, and a divergence from the Thrift/JDBC backend for the identical query. Reported as conformance finding DATATYPE-041 (issue #203).

Establishing ground truth (not trusting the issue's stated cause)

The issue was seeded from the Go reference PR (databricks-sql-go#416) and pointed the fix at type_mapping.rs. I verified the reference behavior empirically before changing anything:

  • SEA wire (decompressed the recorded LZ4 Arrow IPC + a live probe against a SEA warehouse): SELECT NULL genuinely arrives as an Arrow null-typed column, with manifest type_name=NULL, type_text=VOID. So SEA does not stringify VOID on the wire.
  • Thrift/JDBC reference (~/databricks-jdbc): a NULL-named column maps to Types.VARCHAR at the user-facing metadata surface (DatabricksTypeUtil), i.e. STRING. The Go reference PR likewise coerces arrow.NULL -> STRING.
  • The issue's suggested fix location was wrong: type_mapping.rs's VOID -> Null arm only feeds the empty-result/manifest schema path. The live-data path keeps the Arrow-wire null; augment_schema_with_manifest only overlays metadata, never the DataType.

Conclusion: Null is faithful to the SEA wire, but this project's contract is drop-in parity with the Thrift/JDBC reference, which surfaces VOID as STRING. So the kernel now surfaces the server-reported STRING type.

Why the kernel (not each xDBC driver)

The kernel is the shared SEA core that ODBC / ADBC / PyO3 / napi all consume. Coercing here once avoids four divergent copies of the same fix, and it's the layer the tests/kernel/ conformance test asserts against. The server type is preserved in field metadata (databricks.type_name=NULL, type_text=VOID), so a consumer that wants the raw VOID distinction can still recover it — strictly more faithful than the Go driver, which erases it.

Changes

  • reader/post_processor: coerce a live-data Arrow Null column to an all-null Utf8 column. Unconditional (not option-gated) — Null carries no values, so the rewrite is lossless. Composes with manifest augmentation (keeps real column name + metadata).
  • metadata/type_mapping: empty-result/manifest schema maps VOID/NULL → Utf8 (was DataType::Null); JDBC-types surface maps VOID/NULL → VARCHAR (was the JDBC_OTHER sentinel), matching the reference. Keeps the three surfaces (Arrow data, empty-result schema, JDBC types) consistent.
  • Updated the one existing test that pinned the old VOID -> Null behavior (reader/mod.rs).

Test plan

  • New unit tests (reader/post_processor): untyped_null_column_rewritten_to_utf8 (default options, asserts Utf8 + still-NULL value + matches sibling), untyped_null_carries_manifest_metadata_and_real_name (composes with augmentation).
  • New unit tests (metadata/type_mapping): test_databricks_type_to_xdbc_void_null_is_varchar; updated test_databricks_type_to_arrow_special and the manifest interval/void schema test.
  • Live-verified against a SEA warehouse: SELECT NULL AS untyped_null, CAST(NULL AS STRING) AS typed_null_string — both columns now report Utf8, values stay NULL. (Confirmed the pre-fix behavior first: untyped_null=Null, typed=Utf8.)
  • Full suite: 881 passed, 0 failed. cargo fmt + cargo clippy --all-targets -D warnings clean.

Closes #203

This pull request and its description were written by Isaac.

JSON-text mode rendered nested complex-type leaves with layouts that
diverge from the shared driver-conformance spec:

- DOUBLE leaves used Rust's `{}` f64 formatter (shortest round-trip),
  so `100.0` rendered `100`, `1.0E-4` rendered `0.0001`, `1.0E21`
  rendered as a 22-digit integer, and `3.2033798725730455E8` rendered
  `320337987.25730455` (COMPLEX-015).
- TIMESTAMP leaves used ISO-8601 with a 'T' separator, fixed-width
  fractional seconds, and a 'Z' suffix (`2025-01-24T07:07:41.000000Z`)
  instead of the wall-clock spelling the top-level TIMESTAMP-to-text
  path produces (COMPLEX-016).

Replace `append_float` with `java_double_to_string`, which reproduces
the JVM's `Double.toString` layout (forced fraction, capital 'E',
unsigned/unpadded exponent, switch at exp >= 7 or < -3) — the layout
the shared spec pins and the reference drivers emit. Render nested
TIMESTAMP leaves as the space-separated wall clock with trailing-zero
fractions stripped and no offset suffix.

The reference behavior was verified empirically against the OSS JDBC
driver (`Double.toString`) and the shared conformance spec rather than
taken from the issue text: JDBC's `Double.toString` is exactly the
DOUBLE layout, while the TIMESTAMP target follows the spec/ODBC
wall-clock spelling (JDBC itself is buggy for the nested TIMESTAMP
case). The two pre-existing timestamp tests that encoded the old
'T'/'Z' spelling are updated to the corrected wall-clock output.

Closes #219

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
…Thrift

An untyped NULL column (`SELECT NULL`, VOID) was reporting Arrow
`DataType::Null` while a `CAST(NULL AS STRING)` sibling in the same
query reported `Utf8` — a self-inconsistent result set and a divergence
from the Thrift/JDBC backend for the identical query.

SEA genuinely sends an Arrow `null`-typed column on the wire for
`SELECT NULL` (confirmed by decompressing the recorded Arrow IPC and a
live probe: `type_name=NULL`, `type_text=VOID`, Arrow `Null`). That is
faithful to the wire but diverges from the reference: Thrift/JDBC
surfaces VOID as STRING (`DatabricksTypeUtil` maps a NULL-named column
to `Types.VARCHAR`), and the Go reference driver (#416) likewise coerces
`arrow.NULL -> STRING`. This project's contract is drop-in parity with
that reference, so the kernel now surfaces the server-reported STRING.

Fix (kernel, the shared SEA core all xDBC/PyO3/napi drivers consume, so
the coercion lives here once rather than in each driver):

- `post_processor`: coerce a live-data Arrow `Null` column to an
  all-null `Utf8` column. Unconditional (not option-gated) — a `Null`
  column carries no values, so the rewrite is lossless. The server type
  is preserved in field metadata (`databricks.type_name=NULL`,
  `type_text=VOID`), so consumers wanting the raw distinction can still
  recover it — strictly more faithful than the Go driver, which drops it.
- `type_mapping`: empty-result/manifest schema maps `VOID`/`NULL` to
  `Utf8` (was `DataType::Null`), so an empty VOID result is consistent
  with the live-data path; and the JDBC-types surface maps `VOID`/`NULL`
  to `VARCHAR` (was the `JDBC_OTHER` sentinel), matching the reference.

Verified live against a SEA warehouse: both `untyped_null` and
`typed_null_string` now report `Utf8`; value stays NULL.

Closes #203

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 Low

The core change — surfacing untyped NULL/VOID columns as STRING (Utf8) — is correct, lossless, well-tested, and composes cleanly with manifest augmentation across all three surfaces (Arrow data, empty-result schema, JDBC types). One caveat: this PR (titled/described solely around #203/VOID) also bundles two substantial, undisclosed changes to src/reader/post_processor/json.rs — a reversal of the nested-TIMESTAMP text format (dropping T/Z, and retiring the ..._keeps_nine_digits_and_z test that previously asserted Thrift Z parity) and a new java_double_to_string formatter. I verified the double formatter is correct on its boundary cases and that the timestamp direction matches the JDBC reference; the only open question is the whole-seconds .0 fraction (see inline low). Worth surfacing that these belong in their own PR / description given one of them intentionally reverses a previously-asserted parity behavior.

// precisely the wall-clock spelling; the Arrow `tz` is not
// rendered (the instant is already the wall clock).
let _ = tz;
let s = dt.format("%Y-%m-%d %H:%M:%S%.f").to_string();

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 new nested-TIMESTAMP spelling uses %.f, which omits the fractional part entirely for whole seconds (2025-01-24 07:07:41, asserted in nested_timestamp_leaf_uses_wall_clock_spelling). The direction of this change is correct — the JDBC reference renders nested timestamps via java.sql.Timestamp.toString(), which uses a space separator and no T/Z, so the previous %Y-%m-%dT...Z form (and the retired ..._keeps_nine_digits_and_z test) was the divergent one. However, java.sql.Timestamp.toString() always emits at least a single fractional digit for whole seconds (2025-01-24 07:07:41.0), whereas %.f drops the point altogether. If the intended parity target here is JDBC, whole-second nested timestamps will byte-mismatch (missing .0). The comment cites ODBC issue #197 / COMPLEX-016 as the spec instead, so this may be deliberate — please confirm the trailing-.0 behavior against that spec (and the top-level TIMESTAMP-to-text path this claims to mirror), since the two references disagree on this point.

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit c0f023d Aug 10, 2026
19 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — eaf4b5eb Deployed Aug 10, 2026 by oss-reviewer-bot[bot] via followup #247
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.

[coverage] Conformance findings: DATATYPE-041

1 participant