Repository navigation
Fix icebergBucket for timestamp_ns values before 1970 - #125351
PedroTadim merged 3 commits into
Conversation
icebergHash converted a DateTime64(9) value to microseconds with integer division, which rounds toward zero. The Iceberg spec hashes microsecsFromUnixEpoch, and Java Iceberg computes it with DateTimeUtil.nanosToMicros = Math.floorDiv(nanos, 1000). For a value before 1970 with a sub-microsecond part the two differ by one microsecond, so icebergBucket returned a different bucket than other engines: Iceberg partition pruning skipped the data file that holds the row (the query returned no rows), and INSERT wrote such rows into a non-spec bucket. All bucket consumers (manifest pruning, ChunkPartitioner, DROP PARTITION) call the function, so the conversion is fixed at that single site. The temporal transforms already floor (b79c31a). ClickHouse#125330 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (3 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261012-083800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261012-081900 |
|
Workflow [PR], commit [314d186] Summary: ✅
AI ReviewSummaryThe PR fixes Findings❌ Blockers
Tests
Final Verdict❌ Block. Provide compatibility/migration handling for previously stored hash values and regression coverage proving existing rows remain queryable. |
| { | ||
| value_int = value_int / 1000; | ||
| } | ||
| value_int = value_int / 1000 - (value_int % 1000 < 0 ? 1 : 0); |
There was a problem hiding this comment.
This fixes future timestamp_ns hashing, but it also changes the partition/key value that ClickHouse computes for already-written pre-1970 DateTime64(9) values with sub-microsecond digits. The PR description already calls out the consequence: after upgrade, exact predicates on those values prune to the new spec bucket and silently miss rows that older ClickHouse builds wrote into the old bucket with the default use_iceberg_partition_pruning = 1; the same compatibility break applies to MergeTree keys built on icebergBucket / icebergHash.
That is a wrong-answer risk on existing data, not just a forward fix. Please add a migration/compatibility path before flipping the default semantics here — for example by probing both the old and corrected bucket for the affected domain, or by gating the new hash behind a setting plus a documented rewrite procedure for existing data.
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - f668011Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261012-180013 |
|
Fixing PR for the Performance Comparison (arm_release, master_head, 6/6) join_nullable_keys_small_table row: #125542 |
|
@groeneai 🕵️ src/Functions/icebergDateTransforms.cpp already has floorDivide(Int64, Int64), added in #119579 for the temporal transforms, in an anonymous namespace. Could it move to a small shared header next to these functions, so that this line becomes value_int = floorDivide(value_int, 1000);? Then every Iceberg transform that turns nanoseconds into a coarser unit uses one floor rule. A future fix of that rule, or a new transform, can't miss one of the copies, and the expression no longer needs a comment. |
Move floorDivide from the anonymous namespace of icebergDateTransforms.cpp to src/Functions/icebergCommon.h and use it for the nanoseconds to microseconds conversion in icebergHash, so every Iceberg transform that converts to a coarser time unit uses the same floor rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Done in 314d186: |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
icebergBucketandicebergHashforDateTime64(9)values (Icebergtimestamp_nsandtimestamptz_ns) before 1970 that have a sub-microsecond part: nanoseconds are now floored to microseconds as the Iceberg spec requires, so partition pruning no longer skips the files that hold such rows, andINSERTwrites them into the same bucket as other engines. Closes #125330.Description
On 26.8.18.2 (and 26.3.42.3),
icebergBucket(16, toDateTime64('1969-12-31 23:59:59.999999999', 9, 'UTC'))returns 12 instead of the spec's 8, so on atimestamp_nsIceberg table partitioned bybucket[N]and written by another engine,WHERE ts = <such a value>returns no rows with the defaultuse_iceberg_partition_pruning = 1.Root cause:
icebergHashconverted nanoseconds to microseconds withvalue / 1000, which rounds toward zero. The spec hashesmicrosecsFromUnixEpoch(v), and Java Iceberg computes it withMath.floorDiv(nanos, 1000)(DateTimeUtil.nanosToMicros). For a value before 1970 with a sub-microsecond part the two differ by one microsecond, so the hash and the bucket differ. Manifest pruning, theINSERTpartitioner andDROP PARTITIONall call the function, so the conversion is floored at that one site, with thefloorDividehelper the temporal transforms already use (#119579), now shared insrc/Functions/icebergCommon.h.Validation: the new test pins the values Java Iceberg 1.10 returns (cross-checked with an independent Murmur3 implementation) and fails on master. On the Java-written table from #125329, an equality filter on each row now returns the same rows with pruning on and off (4 of 9 rows were lost on master), and an
INSERTof1969-12-31 23:59:59.999999999writes bucket 8 instead of 12.#125329 skips bucket pruning for 1969 values in
05369because of this issue; the skip can be dropped once both are merged.Data that ClickHouse already keyed by the old value stays there: an equality filter on exactly such a value now skips Iceberg rows that a ClickHouse
INSERTput in the old bucket (other engines already did), and likewise MergeTree parts whosePARTITION BYorORDER BYappliesicebergBucketoricebergHashto such values.Workflow [PR]
Sync PR [sync-upstream/pr/125351]
Version info
26.11.1.52-master(included in26.11and later)