-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33315][SQL] Simplify CaseWhen with EqualTo #30222
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
Changes from all commits
3a1cd10
593678c
ee5e6dd
5af6ab3
b611659
7d7eca3
5a90bfc
0099d2a
312c613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -523,6 +523,16 @@ object SimplifyConditionals extends Rule[LogicalPlan] with PredicateHelper { | |
| } else { | ||
| e.copy(branches = branches.take(i).map(branch => (branch._1, elseValue))) | ||
| } | ||
|
|
||
| case e @ EqualTo(c @ CaseWhen(branches, elseValue), right) | ||
| if c.deterministic && | ||
| right.isInstanceOf[Literal] && branches.forall(_._2.isInstanceOf[Literal]) && | ||
| elseValue.forall(_.isInstanceOf[Literal]) => | ||
| if ((branches.map(_._2) ++ elseValue).forall(!_.equals(right))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use an |
||
| FalseLiteral | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's update the JIRA/PR title, as it's a different optimization now.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } else { | ||
| e | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
More precisely, I think we only need to make sure the skipped branches are all deterministic.