[SPARK-48016][SQL][3.4] Fix a bug in try_divide function when with decimals#46289
Closed
gengliangwang wants to merge 1 commit intoapache:branch-3.4from
Closed
[SPARK-48016][SQL][3.4] Fix a bug in try_divide function when with decimals#46289gengliangwang wants to merge 1 commit intoapache:branch-3.4from
gengliangwang wants to merge 1 commit intoapache:branch-3.4from
Conversation
Currently, the following query will throw DIVIDE_BY_ZERO error instead of returning null
```
SELECT try_divide(1, decimal(0));
```
This is caused by the rule `DecimalPrecision`:
```
case b BinaryOperator(left, right) if left.dataType != right.dataType =>
(left, right) match {
...
case (l: Literal, r) if r.dataType.isInstanceOf[DecimalType] &&
l.dataType.isInstanceOf[IntegralType] &&
literalPickMinimumPrecision =>
b.makeCopy(Array(Cast(l, DataTypeUtils.fromLiteral(l)), r))
```
The result of the above makeCopy will contain `ANSI` as the `evalMode`, instead of `TRY`.
This PR is to fix this bug by replacing the makeCopy method calls with withNewChildren
Bug fix in try_* functions.
Yes, it fixes a long-standing bug in the try_divide function.
New UT
No
Closes apache#46286 from gengliangwang/avoidMakeCopy.
Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
(cherry picked from commit 3fbcb26)
Signed-off-by: Gengliang Wang <gengliang@apache.org>
Member
Author
|
This one is to backport #46286 to branch 3.4 |
dongjoon-hyun
approved these changes
Apr 30, 2024
Member
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM (if CI passes)
Member
|
Thank you, @gengliangwang . |
HyukjinKwon
approved these changes
Apr 30, 2024
Member
|
Oh, nvm. It seems that the docker is broken at all branches. |
Member
Author
|
Merging to 3.4 |
gengliangwang
added a commit
that referenced
this pull request
Apr 30, 2024
…cimals
### What changes were proposed in this pull request?
Currently, the following query will throw DIVIDE_BY_ZERO error instead of returning null
```
SELECT try_divide(1, decimal(0));
```
This is caused by the rule `DecimalPrecision`:
```
case b BinaryOperator(left, right) if left.dataType != right.dataType =>
(left, right) match {
...
case (l: Literal, r) if r.dataType.isInstanceOf[DecimalType] &&
l.dataType.isInstanceOf[IntegralType] &&
literalPickMinimumPrecision =>
b.makeCopy(Array(Cast(l, DataTypeUtils.fromLiteral(l)), r))
```
The result of the above makeCopy will contain `ANSI` as the `evalMode`, instead of `TRY`.
This PR is to fix this bug by replacing the makeCopy method calls with withNewChildren
### Why are the changes needed?
Bug fix in try_* functions.
### Does this PR introduce _any_ user-facing change?
Yes, it fixes a long-standing bug in the try_divide function.
### How was this patch tested?
New UT
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #46289 from gengliangwang/PICK_PR_46286_BRANCH-3.4.
Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
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 changes were proposed in this pull request?
Currently, the following query will throw DIVIDE_BY_ZERO error instead of returning null
This is caused by the rule
DecimalPrecision:The result of the above makeCopy will contain
ANSIas theevalMode, instead ofTRY.This PR is to fix this bug by replacing the makeCopy method calls with withNewChildren
Why are the changes needed?
Bug fix in try_* functions.
Does this PR introduce any user-facing change?
Yes, it fixes a long-standing bug in the try_divide function.
How was this patch tested?
New UT
Was this patch authored or co-authored using generative AI tooling?
No