Commit 2fb8dff
[SPARK-46632][SQL] Fix subexpression elimination when equivalent ternary expressions have different children
### What changes were proposed in this pull request?
Remove unexpected exception thrown in `EquivalentExpressions.updateExprInMap()`. Equivalent expressions may contain different children, it should happen expression not in map and `useCount` is -1.
For example, before this PR will throw IllegalStateException
```
Seq((1, 2, 3), (2, 3, 4)).toDF("a", "b", "c")
.selectExpr("case when a + b + c>3 then 1 when c + a + b>0 then 2 else 0 end as d").show()
```
### Why are the changes needed?
Bug fix.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
New unit test, before this PR will throw IllegalStateException: *** with use count: -1
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #46135 from zml1206/SPARK-46632.
Authored-by: zml1206 <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>1 parent f33aa0a commit 2fb8dff
File tree
2 files changed
+12
-4
lines changed- sql/catalyst/src
- main/scala/org/apache/spark/sql/catalyst/expressions
- test/scala/org/apache/spark/sql/catalyst/expressions
2 files changed
+12
-4
lines changedLines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 83 | | |
88 | 84 | | |
89 | 85 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
497 | 509 | | |
498 | 510 | | |
499 | 511 | | |
| |||
0 commit comments