[fix](nereids) Fix divide-by-zero guard in divideDecimal constant folding#64675
Open
LuciferYang wants to merge 2 commits into
Open
[fix](nereids) Fix divide-by-zero guard in divideDecimal constant folding#64675LuciferYang wants to merge 2 commits into
LuciferYang wants to merge 2 commits into
Conversation
…ding divideDecimal checked the numerator (first) instead of the denominator (second) when guarding against division by zero. As a result DECIMALV2 constant folding evaluated 0 / x as NULL instead of 0, and x / 0 threw ArithmeticException (caught by ExpressionEvaluator and left unfolded). Guard on second, matching divideDouble and divideDecimalV3. Adds regression tests for both cases.
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
2 tasks
…nt dispatch Adds a FoldConstantRuleOnFE-level test that builds Divide over two DecimalV2 (DecimalLiteral) operands and verifies the full dispatch: 0 / 5 folds to decimal 0 (not NULL) and 5 / 0 folds to NULL. Complements the existing direct unit tests on the executable helper.
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
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.
What problem does this PR solve?
Issue Number: close #64681
Problem Summary:
NumericArithmetic.divideDecimal(the DECIMALV2 constant-foldingdividefunction) guarded against division by zero by checking the numerator (first) instead of the denominator (second):As a result, when both operands are DECIMALV2 literals:
0 / xfolded to NULL instead of0— a silent wrong result.x / 0skipped the guard and calledBigDecimal.divide(ZERO), throwingArithmeticException. This is caught byExpressionEvaluator.invokeand the expression is left unfolded (BE then evaluates it and returns NULL), so it is not a crash, but the FE folding path is incorrect.The sibling functions
divideDoubleanddivideDecimalV3both correctly checksecond. This PR alignsdivideDecimalwith them by checking the denominator. Division by zero continues to return NULL, matching Doris/MySQL semantics (Doris is MySQL-compatible here; it does not raise the ANSIdivision by zeroerror).Release note
Fix incorrect constant folding of DECIMALV2 division:
0 / xwas folded to NULL instead of 0.Check List (For Author)
Test
testDivideDecimalZeroNumeratorandtestDivideDecimalZeroDenominatorinNumericArithmeticTest)Behavior changed:
0 / xover constant DECIMALV2 values now correctly folds to0instead ofNULL. Division by zero still returns NULL (unchanged).Does this need documentation?