xiaoh1024 opened a new pull request, #58967: URL: https://github.com/apache/spark/pull/58967
### What changes were proposed in this pull request? Extend `SimplifyConditionals` to remove later CASE branches whose deterministic condition is semantically equal to an earlier one, preserving the first branch and the order of the remaining branches. For example, `CASE WHEN a > 0 THEN a WHEN a > 0 THEN b ELSE 0 END` becomes `CASE WHEN a > 0 THEN a ELSE 0 END`. ### Why are the changes needed? The repeated branch cannot be selected but remains in the optimized plan. Removing it avoids a redundant condition check and can enable pruning columns used only by that branch. ### Does this PR introduce _any_ user-facing change? Yes. Optimized plans omit the unreachable branches. Query results are unchanged. ### How was this patch tested? Added optimizer tests covering equivalent conditions, first-match order, NULLs, omitted ELSE, non-deterministic conditions and values, and interaction with existing simplifications. Added a SQL regression checking branch removal and results with and without code generation. ### Was this patch authored or co-authored using generative AI tooling? Yes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
