Repository navigation
fix(json): match reference spelling for nested DOUBLE/TIMESTAMP leaves - #232
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>
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
🔵 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.
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.append_floatused Rust's{}f64 formatter (shortest round-trip), so100.0rendered100,1.0E-4rendered0.0001,1.0E21rendered as a 22-digit integer, and3.2033798725730455E8rendered320337987.25730455.DataType::Timestamparm emitted ISO-8601 with aTseparator, fixed-width fractional seconds, and aZsuffix (2025-01-24T07:07:41.000000Z) instead of the wall-clock spelling the top-level TIMESTAMP-to-text path produces.Fix
append_floatwithjava_double_to_string, which reproduces the JVM'sDouble.toStringlayout: a forced fractional part, capitalE, and an unsigned/unpadded exponent, switching to scientific notation when the decimal exponent is>= 7or< -3. It reuses Rust's shortest round-trip digits ({:e}) and only re-lays them out, so the round-trip value is unchanged.%Y-%m-%d %H:%M:%S%.f): noT, noZ/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.toString, which is exactly the spec's forced-fraction / capital-E/ unpadded-exponent layout. Cross-checked every value and boundary (1e7→1.0E7,9999999.0plain,0.001plain,0.0001→1.0E-4,-0.0→-0.0) against a JVM probe.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
nested_double_leaf_uses_java_double_layout— asserts the full struct/array/map DOUBLE leaf token set from the spec contract.java_double_layout_switch_boundaries— pins the plain↔scientific switch, sign, and negative zero.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.timestamp_microsecond_precision_preserved,timestamp_nanosecond_with_tz_keeps_nine_digits_no_z) that encoded the oldT/Zspelling to the corrected wall-clock output.cargo test(full suite, 743 lib tests + doc tests),cargo clippy --all-targets, andcargo fmtall 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.