fix: SMALLINT addition overflow should error instead of silently wrapping#21319
Open
xiedeyantu wants to merge 5 commits intoapache:mainfrom
Open
fix: SMALLINT addition overflow should error instead of silently wrapping#21319xiedeyantu wants to merge 5 commits intoapache:mainfrom
xiedeyantu wants to merge 5 commits intoapache:mainfrom
Conversation
Member
Author
|
The datafusion-testing repository should be updated to align with this change. I have forked the datafusion-testing project on my GitHub and submitted a apache/datafusion-testing#18. I'm not sure about the merging process. The current step is to update the submodule using the datafusion-testing PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
DataFusion was silently wrapping on integer arithmetic overflow instead of returning an error. For example:
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 offail_on_overflowfromfalsetotrue. This causes+,-, and*on integer types to use Arrow's checked kernels instead of the wrapping variants, returning an error on overflow.dynamic_filters.rsandphysical_planner.rsto reflect the new default.explain_analyze.sltto use slt:ignore foroutput_byteson integer arithmetic projections, since Arrow's checked kernels may allocate a validity buffer, slightly changing the reported byte size.operator.sltcovering overflow forTINYINT,SMALLINT,INT, andBIGINTwith+,-, and*.Are these changes tested?
Yes.
operator.sltverify that overflow on all integer widths (Int8,Int16,Int32,Int64) returns an error for addition, subtraction, and multiplication.test_add_with_overflow,test_subtract_with_overflow, andtest_mul_with_overflowinbinary.rscontinue to pass (they already usedwith_fail_on_overflow(true)explicitly).Are there any user-facing changes?
Yes. Integer arithmetic (
+,-,*) on typesTINYINT,SMALLINT,INT, andBIGINTnow returns an error on overflow instead of silently wrapping. This aligns DataFusion's behavior with DuckDB and PostgreSQL.