fix(transform): floor nanosecond timestamps before bucket hashing - #2891
Open
fallintoplace wants to merge 1 commit into
Open
fix(transform): floor nanosecond timestamps before bucket hashing#2891fallintoplace wants to merge 1 commit into
fallintoplace wants to merge 1 commit into
Conversation
fallintoplace
force-pushed
the
fix-bucket-negative-nanos
branch
from
July 25, 2026 15:59
ac681e5 to
cb83680
Compare
xanderbailey
approved these changes
Jul 27, 2026
xanderbailey
left a comment
Contributor
There was a problem hiding this comment.
Checked this against Java implementation and it does do the same. Thanks for the PR!
| } | ||
|
|
||
| #[inline] | ||
| fn nanos_to_micros(v: i64) -> i64 { |
Contributor
There was a problem hiding this comment.
| fn test_nanos_to_micros_uses_floor_division() { | ||
| assert_eq!(Bucket::nanos_to_micros(1_001), 1); | ||
| assert_eq!(Bucket::nanos_to_micros(1_000), 1); | ||
| assert_eq!(Bucket::nanos_to_micros(-1_000), -1); |
Contributor
There was a problem hiding this comment.
Maybe worth a sanity check for 0, i64::Min and i64::Max
fallintoplace
force-pushed
the
fix-bucket-negative-nanos
branch
from
July 27, 2026 08:37
cb83680 to
24e6ccd
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.
Which issue does this PR close?
N/A. Found while comparing the Rust bucket transform with the Java reference implementation.
What changes are included in this PR?
Rust integer division truncates toward zero, while Iceberg Java converts nanoseconds to microseconds with floor division before bucket hashing. For negative values that are not exactly microsecond-aligned, dividing by 1,000 therefore hashed the wrong microsecond. For example,
-1,001 nsbecame-1 µsinstead of-2 µs, which could place pre-epoch values in a different partition bucket across implementations.This PR centralizes nanosecond-to-microsecond conversion with Euclidean division and uses it for:
Time64values with nanosecond precisionTimestampvalues with nanosecond precisiontimestamp_nsandtimestamptz_nsliteralsPositive and exactly microsecond-aligned values are unchanged.
Are these changes tested?
Yes. Unit tests assert the conversion directly for positive, aligned-negative, and unaligned-negative values, then verify that pre-epoch nanosecond literals and Arrow arrays bucket identically to their equivalent microsecond values.
Validated with:
cargo test -p iceberg transform::bucket::test --libcargo clippy -p iceberg --lib -- -D warnings