-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-31705][SQL][FOLLOWUP] Avoid the unnecessary CNF computation for full-outer joins #28810
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1290,11 +1290,17 @@ object PushPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelper { | |
| (leftEvaluateCondition, rightEvaluateCondition, commonCondition ++ nonDeterministic) | ||
| } | ||
|
|
||
| private def canPushThrough(joinType: JoinType): Boolean = joinType match { | ||
| case _: InnerLike | LeftSemi | RightOuter | LeftOuter | LeftAnti | ExistenceJoin(_) => true | ||
| case _ => false | ||
| } | ||
|
|
||
| def apply(plan: LogicalPlan): LogicalPlan = plan transform applyLocally | ||
|
|
||
| val applyLocally: PartialFunction[LogicalPlan, LogicalPlan] = { | ||
| // push the where condition down into join filter | ||
| case f @ Filter(filterCondition, Join(left, right, joinType, joinCondition, hint)) => | ||
| case f @ Filter(filterCondition, Join(left, right, joinType, joinCondition, hint)) | ||
| if canPushThrough(joinType) => | ||
| val (leftFilterConditions, rightFilterConditions, commonFilterCondition) = | ||
| split(splitConjunctivePredicates(filterCondition), left, right) | ||
| joinType match { | ||
|
|
@@ -1334,13 +1340,13 @@ object PushPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelper { | |
|
|
||
| (rightFilterConditions ++ commonFilterCondition). | ||
| reduceLeftOption(And).map(Filter(_, newJoin)).getOrElse(newJoin) | ||
| case FullOuter => f // DO Nothing for Full Outer Join | ||
| case NaturalJoin(_) => sys.error("Untransformed NaturalJoin node") | ||
| case UsingJoin(_, _) => sys.error("Untransformed Using join node") | ||
|
|
||
| case jt => | ||
| throw new IllegalStateException(s"Unexpected join type: $jt") | ||
|
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.
|
||
| } | ||
|
|
||
| // push down the join filter into sub query scanning if applicable | ||
| case j @ Join(left, right, joinType, joinCondition, hint) => | ||
| case j @ Join(left, right, joinType, joinCondition, hint) if canPushThrough(joinType) => | ||
| val (leftJoinConditions, rightJoinConditions, commonJoinCondition) = | ||
| split(joinCondition.map(splitConjunctivePredicates).getOrElse(Nil), left, right) | ||
|
|
||
|
|
@@ -1370,9 +1376,9 @@ object PushPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelper { | |
| val newJoinCond = (leftJoinConditions ++ commonJoinCondition).reduceLeftOption(And) | ||
|
|
||
| Join(newLeft, newRight, joinType, newJoinCond, hint) | ||
| case FullOuter => j | ||
| case NaturalJoin(_) => sys.error("Untransformed NaturalJoin node") | ||
| case UsingJoin(_, _) => sys.error("Untransformed Using join node") | ||
|
|
||
| case jt => | ||
| throw new IllegalStateException(s"Unexpected join type: $jt") | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,15 @@ import org.apache.spark.sql.catalyst.rules.Rule | |
| * when predicate pushdown happens. | ||
| */ | ||
| object PushCNFPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelper { | ||
|
|
||
| private def canPushThrough(joinType: JoinType): Boolean = joinType match { | ||
| case _: InnerLike | LeftSemi | RightOuter | LeftOuter | LeftAnti | ExistenceJoin(_) => true | ||
| case _ => false | ||
| } | ||
|
|
||
| def apply(plan: LogicalPlan): LogicalPlan = plan transform { | ||
| case j @ Join(left, right, joinType, Some(joinCondition), hint) => | ||
| case j @ Join(left, right, joinType, Some(joinCondition), hint) | ||
| if canPushThrough(joinType) => | ||
| val predicates = conjunctiveNormalForm(joinCondition) | ||
| if (predicates.isEmpty) { | ||
| j | ||
|
|
@@ -53,9 +60,8 @@ object PushCNFPredicateThroughJoin extends Rule[LogicalPlan] with PredicateHelpe | |
| Join(newLeft, right, RightOuter, Some(joinCondition), hint) | ||
| case LeftOuter | LeftAnti | ExistenceJoin(_) => | ||
| Join(left, newRight, joinType, Some(joinCondition), hint) | ||
| case FullOuter => j | ||
| case NaturalJoin(_) => sys.error("Untransformed NaturalJoin node") | ||
| case UsingJoin(_, _) => sys.error("Untransformed Using join node") | ||
| case jt => | ||
|
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. ditto |
||
| throw new IllegalStateException(s"Unexpected join type: $jt") | ||
| } | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: jt => other