dragonknightk commented on code in PR #3573:
URL: https://github.com/apache/iceberg-rust/pull/3573#discussion_r4420432278
##########
crates/iceberg/src/transform/truncate.rs:
##########
@@ -968,6 +981,30 @@ mod test {
assert_eq!(res, Datum::int(-10),);
}
+ #[test]
+ fn test_truncate_int_matches_java_wrapping_arithmetic() {
+ // Expected values computed with Iceberg Java's
`TruncateUtil.truncateInt`
+ // (iceberg 1.11.0, JDK 17).
+ for (width, value, expected) in [
+ (2_000_000_000, 1_500_000_000, -2_000_000_000),
+ (i32::MAX as u32, i32::MAX - 1, -2_147_483_647),
+ (1000, i32::MIN, 2_147_483_296),
Review Comment:
Thanks for the careful review, @Baunsgaard! All the nits are addressed in
the updated commit ʕ•ᴥ•ʔ
- Added the "Match Java TruncateUtil" comment above all three helpers. For
the decimal one I worded it slightly differently, since Java's
`truncateDecimal` works on `BigInteger` and never wraps, so the comment there
says the wrapping only keeps out-of-range `i128` values from panicking.
- Renamed the long test to `test_truncate_long_min_matches_java` and turned
it into a loop over your two cases. I also kept the `transform_literal` check
so it lines up with the int test.
- Dropped `wrapping_arithmetic` from the int test name, so it's now
`test_truncate_int_matches_java`.
- Added your two extra int cases. I double-checked all the new expected
values against `TruncateUtil` from iceberg 1.11.0 on JDK 17, and they match
(๑•̀ㅂ•́)و✧
--
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]