laserninja opened a new issue, #18111:
URL: https://github.com/apache/iceberg/issues/18111
### Apache Iceberg version
main (development), commit `c4784768b`
### Query engine
Other: Java API
### Please describe the bug
With an integer partition transform whose width is `Integer.MAX_VALUE`, a
positive value `Integer.MAX_VALUE - 1` is assigned a negative partition key
instead of zero. A table scan filtered by `id >= 0` then excludes the matching
file.
```java
Schema schema = new Schema(Types.NestedField.required(1, "id",
Types.IntegerType.get()));
PartitionSpec spec = PartitionSpec.builderFor(schema).truncate("id",
Integer.MAX_VALUE).build();
int partition = Transforms.<Integer>truncate(Integer.MAX_VALUE)
.bind(Types.IntegerType.get()).apply(Integer.MAX_VALUE - 1);
```
Expected partition: `0`. Actual partition: `-2147483647`.
The regression also computes a `PartitionKey`, appends a data-file entry
carrying it, and checks
`table.newScan().filter(Expressions.greaterThanOrEqual("id", 0)).planFiles()`.
The matching file is omitted.
`TruncateUtil` overflows while adding the positive remainder to the width,
before the second remainder operation. This differs from an inherently
unrepresentable final partition value: all inputs and the correct result here
fit in an int. Related decimal/final-result overflow discussions: #12915 and
#17027.
Proposed fix: use an overflow-safe nonnegative remainder for int and the
narrower integer helpers. Include transform arithmetic and scan-planning
regressions.
### Willingness to contribute
- [x] I can contribute a fix for this bug independently
This report and its reproduction were prepared with AI assistance and
verified locally.
--
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]