-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46632][SQL] Fix subexpression elimination when equivalent ternary expressions have different children #46135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…fferent children throw IllegalStateException
| checkShortcut(Not(And(equal, Literal(false))), 1) | ||
| } | ||
|
|
||
| test("Equivalent ternary expressions have different children") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is because ((1 + 2) + 3) semanticEquals to ((3 + 1) + 2) but their children are different. So when we compute the common elements between the above 2 here:
Lines 112 to 121 in 0d553d0
| var localEquivalenceMap = mutable.HashMap.empty[ExpressionEquals, ExpressionStats] | |
| updateExprTree(exprs.head, localEquivalenceMap) | |
| exprs.tail.foreach { expr => | |
| val otherLocalEquivalenceMap = mutable.HashMap.empty[ExpressionEquals, ExpressionStats] | |
| updateExprTree(expr, otherLocalEquivalenceMap) | |
| localEquivalenceMap = localEquivalenceMap.filter { case (key, _) => | |
| otherLocalEquivalenceMap.contains(key) | |
| } | |
| } |
only ((1 + 2) + 3) remains in localEquivalenceMap but it's children don't. So later when we want to remove ((1 + 2) + 3) we can't find its children...
I think we could fix the above code that computes localEquivalenceMap, but the change in PR is simpler and doesn't seem to do any harm.
|
cc @cloud-fan Do you have time to help take a look? Thank you. |
|
@peter-toth Can this PR be merged? |
|
good catch! merging to master/3.5! |
…ary expressions have different children
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()
```
Bug fix.
No.
New unit test, before this PR will throw IllegalStateException: *** with use count: -1
No.
Closes #46135 from zml1206/SPARK-46632.
Authored-by: zml1206 <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 2fb8dff)
Signed-off-by: Wenchen Fan <[email protected]>
|
Thank you. @cloud-fan @peter-toth |
…ary expressions have different children
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()
```
Bug fix.
No.
New unit test, before this PR will throw IllegalStateException: *** with use count: -1
No.
Closes apache#46135 from zml1206/SPARK-46632.
Authored-by: zml1206 <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
…ary expressions have different children (apache#542) 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() ``` Bug fix. No. New unit test, before this PR will throw IllegalStateException: *** with use count: -1 No. Closes apache#46135 from zml1206/SPARK-46632. Authored-by: zml1206 <[email protected]> (cherry picked from commit 2fb8dff) Signed-off-by: Wenchen Fan <[email protected]> Co-authored-by: zml1206 <[email protected]>
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 anduseCountis -1.For example, before this PR will throw IllegalStateException
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.