adiranjan25 opened a new pull request, #19045:
URL: https://github.com/apache/iceberg/pull/19045

   <h2><span>Summary</span></h2><p><span>This draft PR adds a regression test 
to reproduce integer and long overflow in Apache Iceberg's truncate transform 
when values are near their minimum representable 
limits.</span></p><p><span>Related issue: 
#19023</span></p><h2><span>Problem</span></h2><p><span>The current 
implementation in </span><code><span>TruncateUtil.java</span></code><span> 
calculates:</span></p><pre><code><span>return value - (((value % width) + 
width) % width);</span></code></pre><p><span>For a truncation width of 10, the 
following results occur:</span></p>
   Type | Input | Actual result
   -- | -- | --
   Integer | Integer.MIN_VALUE | 2147483646
   Long | Long.MIN_VALUE | 9223372036854775806
   
   <p><span>In both cases, the mathematical truncated result falls outside the 
representable range of the corresponding Java type, causing arithmetic overflow 
and wraparound to a large positive value.</span></p><p><span>This behavior 
warrants investigation because incorrect partition-transform values may affect 
partition pruning and query 
correctness.</span></p><h2><span>Changes</span></h2><ul><li><p><span>Added 
</span><code><span>testMinimumValueTruncationOverflow()</span></code><span> in 
</span><code><span>TestTruncate.java</span></code><span>.</span></p></li><li><p><span>Reproduced
 the integer overflow through a failing JUnit 
test.</span></p></li><li><p><span>Independently verified both integer and long 
overflow using JShell.</span></p></li><li><p><span>No production implementation 
changes have been made yet.</span></p></li></ul><h2><span>Test 
Results</span></h2><p><span>Executed:</span></p><pre><code><span>./gradlew 
:iceberg-api:test --tests org.apache.iceberg.transforms.TestTrun
 cate --console=plain</span></code></pre><p><span>Result: 9 tests executed, 1 
failed.</span></p><p><span>The new regression test fails at the integer 
assertion, before reaching the long assertion.</span></p><h2><span>Proposed 
Next Steps</span></h2><ol start="1"><li><p><span>Confirm the expected handling 
of truncated values that fall outside the representable integer or long 
range.</span></p></li><li><p><span>Implement overflow-safe behavior while 
considering existing partition 
compatibility.</span></p></li><li><p><span>Refine regression tests to assert 
the agreed behavior for both types 
independently.</span></p></li><li><p><span>Run the relevant API tests before 
marking this PR ready for review.</span></p></li></ol><h2><span>Maintainer 
Feedback Requested</span></h2><p><span>Would explicit overflow detection and 
rejection be the preferred approach for unrepresentable truncation results, or 
is there an established compatibility requirement for these boundary 
cases?</span></p><p><span>T
 his PR is intentionally in draft status while the expected behavior and 
implementation are being finalized.</span></p>


-- 
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