[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.
cc @peter-toth @cloud-fan
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!
Thank you. @cloud-fan @peter-toth