viirya commented on a change in pull request #32303:
URL: https://github.com/apache/spark/pull/32303#discussion_r619571252



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2234,6 +2270,74 @@ class Analyzer(override val catalogManager: 
CatalogManager)
     }
   }
 
+  /**
+   * This rule resolves lateral joins.
+   */
+  object ResolveLateralJoin extends Rule[LogicalPlan] {
+    import ResolveReferences._
+
+    /**
+     * Build a project list for Project/Aggregate and expand the star if 
possible by first using
+     * the inner query plan. If failed, use the outer query plan to expand the 
star and wrap all
+     * expanded attributes in [[OuterReference]]s.
+     */
+    private def expandOuterReference(
+        expressions: Seq[NamedExpression],
+        inner: LogicalPlan,
+        outer: LogicalPlan): Seq[NamedExpression] = {
+
+      def expandInner(star: Star): Seq[NamedExpression] =
+        star.expand(inner, resolver)
+
+      // Leave the star unchanged if the outer plan is unable to resolve the 
star.
+      // Otherwise wrap the resolved attributes in outer references.
+      def expandOuter(star: Star): Seq[NamedExpression] = {
+        star.expand(outer, resolver).map {
+          case s: Star => s
+          case other => other
+            .transform { case a: Attribute => OuterReference(a) }
+            .asInstanceOf[NamedExpression]
+        }
+      }
+
+      buildExpandedProjectList(
+        buildExpandedProjectList(expressions, inner, expandInner),

Review comment:
       If inner `buildExpandedProjectList` was fully resolved, do we still need 
run outer `buildExpandedProjectList`?




-- 
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]

Reply via email to