xiedeyantu opened a new pull request, #21319: URL: https://github.com/apache/datafusion/pull/21319
## Which issue does this PR close? - Closes #21318 . ## Rationale for this change DataFusion was silently wrapping on integer arithmetic overflow instead of returning an error. For example: ``` SELECT CAST(32767 AS SMALLINT) + CAST(2 AS SMALLINT); -- Before: -32767 (silent wrapping) -- After: Error: Arithmetic overflow: Overflow happened on: 32767 + 2 ``` This behavior is incorrect. DuckDB and PostgreSQL both return an error on integer overflow, which is the expected behavior for SQL engines. ## What changes are included in this PR? - `BinaryExpr::new (binary.rs)`: Change the default value of `fail_on_overflow` from `false` to `true`. This causes `+`, `-`, and `*` on integer types to use Arrow's checked kernels instead of the wrapping variants, returning an error on overflow. - Update snapshot assertions in `dynamic_filters.rs` and `physical_planner.rs` to reflect the new default. - Update `explain_analyze.slt` to use slt:ignore for `output_bytes` on integer arithmetic projections, since Arrow's checked kernels may allocate a validity buffer, slightly changing the reported byte size. - Add sqllogictest cases in `operator.slt` covering overflow for `TINYINT`, `SMALLINT`, `INT`, and `BIGINT` with `+`, `-`, and `*`. ## Are these changes tested? Yes. - New query error tests in `operator.slt`verify that overflow on all integer widths (`Int8`, `Int16`, `Int32`, `Int64`) returns an error for addition, subtraction, and multiplication. - Existing tests `test_add_with_overflow`, `test_subtract_with_overflow`, and `test_mul_with_overflow`in `binary.rs`continue to pass (they already used `with_fail_on_overflow(true)`explicitly). ## Are there any user-facing changes? Yes. Integer arithmetic (`+`, `-`, `*`) on types `TINYINT`, `SMALLINT`, `INT`, and `BIGINT` now returns an error on overflow instead of silently wrapping. This aligns DataFusion's behavior with DuckDB and PostgreSQL. -- 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]
