Skip to content

fix(json): match reference spelling for nested DOUBLE/TIMESTAMP leaves - #232

Merged
vikrantpuppala merged 1 commit into
mainfrom
fix/219-nested-double-timestamp-leaf-text
Aug 10, 2026
Merged

vikrantpuppala merged 1 commit into
mainfrom
fix/219-nested-double-timestamp-leaf-text

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Summary

Fixes the two conformance findings in #219 (COMPLEX-015, COMPLEX-016): in JSON-text mode (databricks.complex_types_as_json=true), the kernel rendered nested complex-type leaves with layouts that diverge from the shared driver-conformance spec.

  • COMPLEX-015 (DOUBLE): append_float 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-016 (TIMESTAMP): the DataType::Timestamp arm emitted 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.

Fix

  • Replace append_float with java_double_to_string, which reproduces the JVM's Double.toString layout: a forced fractional part, capital E, and an unsigned/unpadded exponent, switching to scientific notation when the decimal exponent is >= 7 or < -3. It reuses Rust's shortest round-trip digits ({:e}) and only re-lays them out, so the round-trip value is unchanged.
  • Render nested TIMESTAMP leaves as the space-separated wall clock (%Y-%m-%d %H:%M:%S%.f): no T, no Z/offset suffix, trailing-zero fractional seconds stripped (whole seconds carry no fraction).

Reference verification

Per the driver-parity workflow, the target behavior was verified empirically, not taken from the issue text (the issue was seeded from the ODBC driver's spec):

  • DOUBLE: confirmed live that the OSS JDBC driver renders nested DOUBLE leaves through the JVM's Double.toString, which is exactly the spec's forced-fraction / capital-E / unpadded-exponent layout. Cross-checked every value and boundary (1e7 → 1.0E7, 9999999.0 plain, 0.001 plain, 0.0001 → 1.0E-4, -0.0 → -0.0) against a JVM probe.
  • TIMESTAMP: the reference here is the shared spec / ODBC wall-clock spelling (2025-01-24 07:07:41, no .000000/Z), which matches the top-level TIMESTAMP-to-text path. Note JDBC's own nested-TIMESTAMP rendering is itself a confirmed bug (raw epoch microseconds), so JDBC is not the reference for COMPLEX-016.

Test plan

  • Added nested_double_leaf_uses_java_double_layout — asserts the full struct/array/map DOUBLE leaf token set from the spec contract.
  • Added java_double_layout_switch_boundaries — pins the plain↔scientific switch, sign, and negative zero.
  • Added nested_timestamp_leaf_uses_wall_clock_spelling — asserts whole-second (2025-01-24 07:07:41) and fractional (2024-01-15 12:30:45.123456) leaves.
  • Both new leaf tests fail before the fix and pass after.
  • Updated the two pre-existing timestamp tests (timestamp_microsecond_precision_preserved, timestamp_nanosecond_with_tz_keeps_nine_digits_no_z) that encoded the old T/Z spelling to the corrected wall-clock output.
  • cargo test (full suite, 743 lib tests + doc tests), cargo clippy --all-targets, and cargo fmt all clean.

Coverage PR carrying the reproducing xfail tests: https://github.com/databricks/databricks-driver-test/pull/1170

Closes #219

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>

@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

Looks good — the JVM Double.toString reimplementation is correct (switch thresholds, forced-fraction/capital-E layout, negative zero, sign) and well-covered by boundary tests, and the TIMESTAMP wall-clock change with %.f matches the asserted spelling. One non-blocking Low note about the Float32 arm sharing this DOUBLE formatter after widening — pre-existing and worth confirming against the FLOAT conformance expectation, not a regression.

// Rust's `{}` formatter for f64 uses the shortest round-trippable
// representation, matching Java's `Double.toString`.
write!(out, "{v}").unwrap();
out.push_str(&java_double_to_string(v));

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 — java_double_to_string is now the reference-spelling formatter for DOUBLE leaves, but the Float32 arm also routes through append_float after widening v as f64 (line ~104). Because a widened f32 no longer knows it was a 32-bit value, format!("{:e}", ...) produces the shortest round-trip of the f64, not of the original f32 — e.g. a nested FLOAT leaf of 0.1f32 renders as 0.10000000149011612 rather than the 0.1 that Java's Float.toString (the reference for a REAL/FLOAT leaf) would produce.

This is pre-existing (the old {} formatter had the same widening issue) and out of this PR's stated COMPLEX-015 scope, so it isn't a regression. Flagging only to confirm: if the shared conformance spec expects nested FLOAT leaves to follow Float.toString, this path will diverge and warrants a separate follow-up (format the f32 before widening). If the reference widens FLOAT to double anyway, no action needed.

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

This branch was previously deployed

1 inactive deployment
azure-prod — 94e55b55 Deployed Aug 10, 2026 by oss-reviewer-bot[bot] via followup #244
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: COMPLEX-015,COMPLEX-016

1 participant