-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24402] [SQL] Optimize In expression when only one element in the collection or collection is empty
#21442
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 3 commits
7c44c70
449613a
7a354fc
fa678f8
61824f7
23fedd8
5079833
c519c40
9174a30
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 |
|---|---|---|
|
|
@@ -219,10 +219,15 @@ object ReorderAssociativeOperator extends Rule[LogicalPlan] { | |
| object OptimizeIn extends Rule[LogicalPlan] { | ||
| def apply(plan: LogicalPlan): LogicalPlan = plan transform { | ||
| case q: LogicalPlan => q transformExpressionsDown { | ||
| case In(v, list) if list.isEmpty && !v.nullable => FalseLiteral | ||
| case In(v, list) if list.isEmpty => | ||
| // When v is not nullable, the following expression will be optimized | ||
| // to FalseLiteral which is tested in OptimizeInSuite.scala | ||
| If(IsNotNull(v), FalseLiteral, Literal(null, BooleanType)) | ||
| case expr @ In(v, list) if expr.inSetConvertible => | ||
| val newList = ExpressionSet(list).toSeq | ||
| if (newList.size > SQLConf.get.optimizerInSetConversionThreshold) { | ||
| if (newList.length == 1) { | ||
| EqualTo(v, newList.head) | ||
|
Member
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. This will fail, since the schema mismatches when the data type is struct. The test cases were added a few days ago. #21425 |
||
| } else if (newList.size > SQLConf.get.optimizerInSetConversionThreshold) { | ||
|
||
| val hSet = newList.map(e => e.eval(EmptyRow)) | ||
| InSet(v, HashSet() ++ hSet) | ||
| } else if (newList.size < list.size) { | ||
|
||
|
|
||
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.
When
list.length == 1, we don't need to createExpressionSet.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.
This is too minor, I'd like to keep the current code and not break the code flow.
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.
Sounds good.