cloud-fan commented on a change in pull request #33284:
URL: https://github.com/apache/spark/pull/33284#discussion_r669609757
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
##########
@@ -701,3 +702,43 @@ object RewriteLateralSubquery extends Rule[LogicalPlan] {
Join(left, newRight, joinType, newCond, JoinHint.NONE)
}
}
+
+/**
+ * This rule optimizes subqueries with OneRowRelation as leaf nodes.
+ */
+object OptimizeOneRowRelationSubquery extends Rule[LogicalPlan] {
+
+ object OneRowSubquery {
+ def unapply(plan: LogicalPlan): Option[Seq[NamedExpression]] = {
+ CollapseProject(EliminateSubqueryAliases(plan)) match {
+ case Project(projectList, _: OneRowRelation) =>
Some(stripOuterReferences(projectList))
+ case _ => None
+ }
+ }
+ }
+
+ /**
+ * Rewrite a subquery expression into one or more expressions. The rewrite
can only be done
+ * if there is no nested subqueries in the subquery plan.
+ */
+ private def rewrite(plan: LogicalPlan): LogicalPlan =
plan.transformUpWithSubqueries {
+ case LateralJoin(left, right @
LateralSubquery(OneRowSubquery(projectList), _, _, _), _, None)
+ if right.plan.subqueriesAll.isEmpty && right.joinCond.isEmpty =>
+ Project(left.output ++ projectList, left)
Review comment:
if the lateral join has a condition, can we just add a filter above
project?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]