-
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
Changes from 2 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 |
|---|---|---|
|
|
@@ -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 => | ||
| sys.error(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. since we are here, can we throw an exception instead?
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. How about Is it better to change them, too?
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. 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.
yea, I know some rules in the optimizer throw |
||
| } | ||
|
|
||
| // 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 => | ||
| sys.error(s"Unexpected join type: $jt") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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 |
||
| sys.error(s"Unexpected join type: $jt") | ||
| } | ||
| } | ||
| } | ||
|
|
||
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