Skip to content

fix(kernel): TIMESTAMP range + DDL affected-rows parity with Thrift#416

Open
mani-mathur-arch wants to merge 2 commits into
mainfrom
mani/sea-kernel-comparator-fixes
Open

fix(kernel): TIMESTAMP range + DDL affected-rows parity with Thrift#416
mani-mathur-arch wants to merge 2 commits into
mainfrom
mani/sea-kernel-comparator-fixes

Conversation

@mani-mathur-arch

Copy link
Copy Markdown
Collaborator

What

Two SEA-via-kernel↔Thrift parity fixes surfaced by the Go comparator (two database/sql connections against the same warehouse, differing only in useKernel). Both are kernel-path-only divergences from the default Thrift path; the fix is entirely Go-side (no kernel/C-ABI change).

  • TIMESTAMP out-of-nanosecond-range wrapping. The kernel Rows path converted arrow timestamps with arrow's ToTime, which forms an int64-nanosecond intermediate (value * unit-multiplier). For a microsecond TIMESTAMP — Databricks' wire unit — that overflows int64 outside ~1678–2262 and silently wraps a valid instant to a wrong one: TIMESTAMP '0001-01-01' scanned back as 1754-08-30, '9999-12-31' as 1816-03-30. Now converts via the unit-specific time.Unix/UnixMilli/UnixMicro constructors, which split into (seconds, nanoseconds) and represent the full 0001–9999 range. The default Thrift path is unaffected — it receives TIMESTAMP as a preformatted server string and never runs this multiply.

  • DDL affected-rows reported as -1 instead of 0. The C ABI returns -1 for "not applicable / unknown" affected-row counts (DDL, SELECT, or a warehouse that doesn't surface the counter — the kernel's num_modified_rows Option<i64> None). The Thrift path reports 0 in those cases, so Result.RowsAffected() diverged: a CREATE/DROP SCHEMA returned -1 on the kernel backend vs 0 on Thrift. The -1 sentinel is now folded to 0; a real DML count (>= 0) passes through unchanged.

Testing

  • TestScanCellTimestampOutOfNanoRange — pins both repro endpoints (0001-01-01, 9999-12-31) plus the int64-ns boundary years; the existing timestamp unit/location tests still pass.
  • TestNormalizeAffectedRows — table test for the sentinel-normalization rule, factored into a pure (untagged) normalizeAffectedRows so it runs under the default CGO_ENABLED=0 build.
  • Verified on both build paths: default pure-Go (CGO_ENABLED=0) and tagged cgo (-tags databricks_kernel, linking the pinned kernel .a) — build + unit tests green on each.

Stacked on mani/sea-kernel-new-items (#412).

Co-authored-by: Isaac

Base automatically changed from mani/sea-kernel-new-items to main July 21, 2026 04:09
The kernel Rows path converted arrow timestamps with arrow's ToTime, which
forms an int64-nanosecond intermediate (value * unit-multiplier). For a
microsecond TIMESTAMP — Databricks' wire unit — that overflows int64 outside
~1678-2262 and silently wraps a valid instant to a wrong one (TIMESTAMP
'0001-01-01' scanned back as 1754-08-30, '9999-12-31' as 1816-03-30).

Convert via the unit-specific time.Unix/UnixMilli/UnixMicro constructors, which
split into (seconds, nanoseconds) internally and represent the full 0001-9999
range Databricks TIMESTAMP allows. The default Thrift path is unaffected — it
receives TIMESTAMP as a preformatted server string and never runs this
multiply — so this closes a kernel-only divergence from Thrift.

TestScanCellTimestampOutOfNanoRange pins both repro endpoints plus the
int64-ns boundary years; the existing unit and location tests still pass.

Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
The C ABI returns -1 for "not applicable / unknown" affected-row counts — DDL,
SELECT, or a warehouse that doesn't surface the counter (the kernel's
num_modified_rows Option<i64> None). The Thrift path reports 0 in those cases,
so Result.RowsAffected() diverged: a CREATE/DROP SCHEMA returned -1 on the
kernel backend and 0 on Thrift.

Fold the -1 sentinel to 0 so RowsAffected() is identical across backends; a
real DML count (>= 0) passes through unchanged. The rule lives in a pure,
untagged normalizeAffectedRows so it is unit-testable in the default
CGO_ENABLED=0 build alongside the other kernel decision helpers.

Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
@mani-mathur-arch
mani-mathur-arch force-pushed the mani/sea-kernel-comparator-fixes branch from 838bb0c to 21ad6fa Compare July 21, 2026 09:16
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.

1 participant