-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23172][SQL] Expand the ReorderJoin rule to handle Project nodes #20345
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
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 |
|---|---|---|
|
|
@@ -222,14 +222,16 @@ object ExtractEquiJoinKeys extends Logging with PredicateHelper { | |
| } | ||
|
|
||
| /** | ||
| * A pattern that collects the filter and inner joins. | ||
| * A pattern that collects the filter and inner joins and skip projections with attributes only. | ||
| * | ||
| * Filter | ||
| * | | ||
| * inner Join | ||
| * / \ ----> (Seq(plan0, plan1, plan2), conditions) | ||
| * Filter plan2 | ||
| * | | ||
| * Project | ||
|
||
| * | | ||
| * inner join | ||
| * / \ | ||
| * plan0 plan1 | ||
|
|
@@ -250,22 +252,23 @@ object ExtractFiltersAndInnerJoins extends PredicateHelper { | |
| val (plans, conditions) = flattenJoin(left, joinType) | ||
| (plans ++ Seq((right, joinType)), conditions ++ | ||
| cond.toSeq.flatMap(splitConjunctivePredicates)) | ||
| case Filter(filterCondition, j @ Join(_, _, _: InnerLike, _, hint)) if hint == JoinHint.NONE => | ||
| val (plans, conditions) = flattenJoin(j) | ||
| case Filter(filterCondition, child) => | ||
| val (plans, conditions) = flattenJoin(child) | ||
| (plans, conditions ++ splitConjunctivePredicates(filterCondition)) | ||
|
|
||
| case p @ Project(_, child) | ||
| // Keep flattening joins when the project has attributes only | ||
| if p.projectList.forall(_.isInstanceOf[Attribute]) => | ||
| flattenJoin(child) | ||
| case _ => (Seq((plan, parentJoinType)), Seq.empty) | ||
| } | ||
|
|
||
| def unapply(plan: LogicalPlan) | ||
| : Option[(Seq[(LogicalPlan, InnerLike)], Seq[Expression])] | ||
| = plan match { | ||
| case f @ Filter(filterCondition, j @ Join(_, _, joinType: InnerLike, _, hint)) | ||
| if hint == JoinHint.NONE => | ||
| Some(flattenJoin(f)) | ||
| case j @ Join(_, _, joinType, _, hint) if hint == JoinHint.NONE => | ||
| Some(flattenJoin(j)) | ||
| case _ => None | ||
| def unapply(plan: LogicalPlan): Option[(Seq[(LogicalPlan, InnerLike)], Seq[Expression])] = { | ||
| val (plans, conditions) = flattenJoin(plan) | ||
| if (plans.size > 1) { | ||
|
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. how about
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. I feel that that condition goes too far in this patten because this patten name |
||
| Some((plans, conditions)) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
How about make it like:
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.
ok, I'll brush up the code based on the suggestion.
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.
I expanded the function logic in the end of
applybecause the logic is enough small: https://github.com/apache/spark/pull/20345/files#diff-17d31b198ff391188311550fcabd1198R119