Repository navigation
fix(reader): surface untyped NULL (VOID) columns as STRING, matching Thrift - #235
Conversation
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>
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
🔵 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.
Summary
An untyped NULL column (
SELECT NULL, VOID) reported ArrowDataType::Nullwhile aCAST(NULL AS STRING)sibling in the same query reportedUtf8— 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:SELECT NULLgenuinely arrives as an Arrownull-typed column, with manifesttype_name=NULL,type_text=VOID. So SEA does not stringify VOID on the wire.~/databricks-jdbc): a NULL-named column maps toTypes.VARCHARat the user-facing metadata surface (DatabricksTypeUtil), i.e. STRING. The Go reference PR likewise coercesarrow.NULL -> STRING.type_mapping.rs'sVOID -> Nullarm only feeds the empty-result/manifest schema path. The live-data path keeps the Arrow-wirenull;augment_schema_with_manifestonly overlays metadata, never theDataType.Conclusion:
Nullis 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 ArrowNullcolumn to an all-nullUtf8column. Unconditional (not option-gated) —Nullcarries no values, so the rewrite is lossless. Composes with manifest augmentation (keeps real column name + metadata).metadata/type_mapping: empty-result/manifest schema mapsVOID/NULL→Utf8(wasDataType::Null); JDBC-types surface mapsVOID/NULL→VARCHAR(was theJDBC_OTHERsentinel), matching the reference. Keeps the three surfaces (Arrow data, empty-result schema, JDBC types) consistent.VOID -> Nullbehavior (reader/mod.rs).Test plan
reader/post_processor):untyped_null_column_rewritten_to_utf8(default options, assertsUtf8+ still-NULL value + matches sibling),untyped_null_carries_manifest_metadata_and_real_name(composes with augmentation).metadata/type_mapping):test_databricks_type_to_xdbc_void_null_is_varchar; updatedtest_databricks_type_to_arrow_specialand the manifest interval/void schema test.SELECT NULL AS untyped_null, CAST(NULL AS STRING) AS typed_null_string— both columns now reportUtf8, values stay NULL. (Confirmed the pre-fix behavior first:untyped_null=Null,typed=Utf8.)cargo fmt+cargo clippy --all-targets -D warningsclean.Closes #203
This pull request and its description were written by Isaac.