allisonwang-db commented on a change in pull request #32303:
URL: https://github.com/apache/spark/pull/32303#discussion_r647112288
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
##########
@@ -315,19 +314,28 @@ object PullupCorrelatedPredicates extends
Rule[LogicalPlan] with PredicateHelper
case ListQuery(sub, children, exprId, childOutputs, conditions) if
children.nonEmpty =>
val (newPlan, newCond) = pullOutCorrelatedPredicates(sub, outerPlans)
ListQuery(newPlan, children, exprId, childOutputs,
getJoinCondition(newCond, conditions))
+ case LateralSubquery(sub, children, exprId, conditions) if
children.nonEmpty =>
+ val (newPlan, newCond) = decorrelate(sub, outerPlans)
+ LateralSubquery(newPlan, children, exprId, getJoinCondition(newCond,
conditions))
}
}
/**
* Pull up the correlated predicates and rewrite all subqueries in an
operator tree..
*/
def apply(plan: LogicalPlan): LogicalPlan = plan.transformUpWithPruning(
- _.containsAnyPattern(SCALAR_SUBQUERY, EXISTS_SUBQUERY, LIST_SUBQUERY)) {
+ _.containsPattern(PLAN_EXPRESSION)) {
case f @ Filter(_, a: Aggregate) =>
rewriteSubQueries(f, Seq(a, a.child))
- // Only a few unary nodes (Project/Filter/Aggregate) can contain
subqueries.
+ // Only a few unary nodes (Project/Filter/Aggregate/LateralJoin) can
contain subqueries.
case q: UnaryNode =>
- rewriteSubQueries(q, q.children)
+ val newPlan = rewriteSubQueries(q, q.children)
+ // Preserve the original output of the node.
+ if (newPlan.output != q.output) {
Review comment:
Nice!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]