dubin555 opened a new pull request, #7338: URL: https://github.com/apache/paimon/pull/7338
### Purpose `FieldSumAgg` performs unchecked arithmetic for TINYINT, SMALLINT, INTEGER, and BIGINT types. When the accumulator overflows, the result silently wraps around (e.g., `Byte.MAX_VALUE + 1` becomes `-128`), producing incorrect aggregation results without any error or warning. This is silent data corruption in the merge-tree SUM aggregation path. The root cause differs by type: - **TINYINT/SMALLINT:** Java promotes operands to `int` for arithmetic, then the `(byte)` or `(short)` cast silently truncates the overflow bits. - **INTEGER/BIGINT:** Standard `+` and `-` wrap around at `MAX_VALUE` / `MIN_VALUE` per Java spec. This fix adds overflow detection to all three affected methods (`agg`, `retract`, `negative`): - For INTEGER and BIGINT: uses `Math.addExact` / `Math.subtractExact` / `Math.negateExact`, which throw `ArithmeticException` on overflow. - For TINYINT and SMALLINT: uses range-checked helper methods that perform arithmetic in `int` width and verify the result fits in `byte` / `short` range before casting. This is consistent with the overflow-protection pattern already used in `DecimalUtils.add()` and `DecimalUtils.subtract()` in the same codebase. ### Tests - `testFieldSumByteOverflow` — TINYINT: verifies normal addition works, positive overflow throws `ArithmeticException`, negative overflow throws, and retract overflow throws. - `testFieldSumShortOverflow` — SMALLINT: same coverage. - `testFieldSumIntOverflow` — INTEGER: same coverage. - `testFieldSumLongOverflow` — BIGINT: same coverage. ### API and Format No API or storage format changes. ### Documentation No new feature introduced. ### Generative AI tooling Generated-by: Claude Code 1.0.0 -- 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]
