adiranjan25 commented on PR #19164:
URL: https://github.com/apache/iceberg/pull/19164#issuecomment-7251810953
Thanks, @Anurag-S1ngh. Following your question, I extended my independent
boundary validation to cover larger truncation widths and identified a
reproducible strict projection correctness failure on commit `a9ab30a5c`.
**Failing scenario:**
- Type: Integer
- Truncation width: `1073741825`
- Source value: `2147483646`
- Predicate: `value <= 1073741822`
- Transformed partition value: `1073741825`
- Expected strict projection evaluation: `false`
- Actual strict projection evaluation: `true`
The source value does not satisfy the original predicate, but the strict
projection evaluates to true.
I isolated the following regression test using the existing helpers in
`TestTruncatesProjection`:
```java
@Test
public void testLargeWidthStrictProjectionOverflow() {
Type type = Types.IntegerType.get();
int width = 1073741825;
int value = 2147483646;
int boundary = 1073741822;
Schema schema = new Schema(optional(1, "value", type));
PartitionSpec spec =
PartitionSpec.builderFor(schema)
.truncate("value", width)
.build();
Object partition = transform(spec, type, value);
assertThat(value <= boundary).isFalse();
assertThat(
evalProjection(
spec,
lessThanOrEqual("value", boundary),
true,
partition))
.as("Strict projection must not match a nonmatching source row")
.isFalse();
}
```
**Actual test output:**
```text
TestTruncatesProjection >
testLargeWidthStrictProjectionOverflow() FAILED
AssertionFailedError:
Strict projection must not match a nonmatching source row
Expecting value to be false but was true
1 test completed, 1 failed
```
The likely underlying cause is intermediate integer overflow in
`TruncateUtil.truncateInt()`:
```java
return value - (((value % width) + width) % width);
```
For the strict LT_EQ projection, transforming `boundary + 1` causes the
intermediate addition to reach `2147483648`, exceeding `Integer.MAX_VALUE`.
I also independently reproduced the intermediate arithmetic overflow in
JShell using `width = Integer.MAX_VALUE` and `value = 2`, where the current
expression returns `2` instead of the mathematically expected `0`.
This appears to be a separate overflow mechanism from the minimum-value
wraparound addressed by this PR, but it can affect the correctness of the
resulting projection.
I have preserved the failing regression test and validation logs. Would you
prefer incorporating this regression into the current PR, or tracking the
large-width arithmetic overflow separately given the potential
backward-compatibility implications?
I'm happy to help investigate and implement the appropriate follow-up.
Thanks again for encouraging the additional boundary investigation.
--
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]