fix(kernel): TIMESTAMP range + DDL affected-rows parity with Thrift#416
Open
mani-mathur-arch wants to merge 2 commits into
Open
fix(kernel): TIMESTAMP range + DDL affected-rows parity with Thrift#416mani-mathur-arch wants to merge 2 commits into
mani-mathur-arch wants to merge 2 commits into
Conversation
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
force-pushed
the
mani/sea-kernel-comparator-fixes
branch
from
July 21, 2026 09:16
838bb0c to
21ad6fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two SEA-via-kernel↔Thrift parity fixes surfaced by the Go comparator (two
database/sqlconnections against the same warehouse, differing only inuseKernel). 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 anint64-nanosecond intermediate (value * unit-multiplier). For a microsecond TIMESTAMP — Databricks' wire unit — that overflowsint64outside ~1678–2262 and silently wraps a valid instant to a wrong one:TIMESTAMP '0001-01-01'scanned back as1754-08-30,'9999-12-31'as1816-03-30. Now converts via the unit-specifictime.Unix/UnixMilli/UnixMicroconstructors, 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
-1for "not applicable / unknown" affected-row counts (DDL, SELECT, or a warehouse that doesn't surface the counter — the kernel'snum_modified_rowsOption<i64>None). The Thrift path reports0in those cases, soResult.RowsAffected()diverged: aCREATE/DROP SCHEMAreturned-1on the kernel backend vs0on Thrift. The-1sentinel is now folded to0; a real DML count (>= 0) passes through unchanged.Testing
TestScanCellTimestampOutOfNanoRange— pins both repro endpoints (0001-01-01,9999-12-31) plus theint64-ns boundary years; the existing timestamp unit/location tests still pass.TestNormalizeAffectedRows— table test for the sentinel-normalization rule, factored into a pure (untagged)normalizeAffectedRowsso it runs under the defaultCGO_ENABLED=0build.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