Commit 2870c76
committed
[SPARK-48016][SQL][3.4] Fix a bug in try_divide function when with decimals
### 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 apache#46289 from gengliangwang/PICK_PR_46286_BRANCH-3.4.
Authored-by: Gengliang Wang <gengliang@apache.org>
Signed-off-by: Gengliang Wang <gengliang@apache.org>1 parent e2f34c7 commit 2870c76
File tree
7 files changed
+1130
-12
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/resources/sql-tests
- analyzer-results
- ansi
- inputs
- results
- ansi
7 files changed
+1130
-12
lines changedLines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
212 | | - | |
| 212 | + | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | | - | |
| 1109 | + | |
1110 | 1110 | | |
1111 | 1111 | | |
1112 | | - | |
| 1112 | + | |
1113 | 1113 | | |
1114 | 1114 | | |
1115 | 1115 | | |
1116 | 1116 | | |
1117 | | - | |
| 1117 | + | |
1118 | 1118 | | |
1119 | | - | |
| 1119 | + | |
1120 | 1120 | | |
1121 | 1121 | | |
1122 | 1122 | | |
1123 | 1123 | | |
1124 | | - | |
| 1124 | + | |
1125 | 1125 | | |
1126 | 1126 | | |
1127 | 1127 | | |
| |||
0 commit comments