dragonknightk opened a new pull request, #3573:
URL: https://github.com/apache/iceberg-rust/pull/3573

   ## Which issue does this PR close?
   
   - Closes #3141.
   
   ## What changes are included in this PR?
   
   `truncate_i32` used `rem_euclid`, while `truncate_i64` and 
`truncate_decimal_i128` used `(v % w + w) % w`. Both shapes differ from Iceberg 
Java's `TruncateUtil`, which relies on `int`/`long` overflow wrapping:
   
   - For `truncate_i32`, `rem_euclid` never overflows, so any width above 
`2^30` produced a different partition value than Java.
   - For the other two, the final subtraction overflowed at the integer 
minimum, panicking in debug builds and wrapping to the Java value only in 
release builds.
   
   All three helpers now use `wrapping_sub` and `wrapping_add`, so every width 
reproduces the Java result in both debug and release builds. The function 
signatures, the public API, and the call sites are unchanged.
   
   ## Are these changes tested?
   
   Three unit tests in `crates/iceberg/src/transform/truncate.rs`, all expected 
values computed with Iceberg Java's `TruncateUtil` (1.11.0, JDK 17):
   
   - `test_truncate_int_matches_java_wrapping_arithmetic` covers the three 
`i32` cases from the issue, through both `transform` on an array and 
`transform_literal`.
   - `test_truncate_long_min_does_not_panic` covers `i64::MIN` with width 1000, 
which used to panic in debug builds.
   - `test_truncate_decimal_i128_min_does_not_panic` pins that the decimal path 
does not panic at `i128::MIN`. That value is outside the range of a 38-digit 
Iceberg decimal and Java's `truncateDecimal` works on `BigInteger`, so there is 
no wrapping result to compare against.
   
   Reverting the three helpers to their previous bodies makes all three tests 
fail, so each one guards the change.
   
   ## AI Disclosure
   
   Codex and Grok Bot, working for dragonknightk, contributed to this code. The 
fix and the expected values were verified against Iceberg Java's `TruncateUtil` 
source.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to