AveryQi115 commented on code in PR #50548:
URL: https://github.com/apache/spark/pull/50548#discussion_r2054646724


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -2320,20 +2348,57 @@ class Analyzer(override val catalogManager: 
CatalogManager) extends RuleExecutor
         e: SubqueryExpression,
         outer: LogicalPlan)(
         f: (LogicalPlan, Seq[Expression]) => SubqueryExpression): 
SubqueryExpression = {
-      val newSubqueryPlan = AnalysisContext.withOuterPlan(outer) {
-        executeSameContext(e.plan)
+      val outerPlanContext = AnalysisContext.get.outerPlans
+      val newSubqueryPlan = if (outerPlanContext.isDefined &&
+        // We don't allow lateral subquery having nested correlation
+        !e.isInstanceOf[LateralSubquery]

Review Comment:
   No, any subqueries within/below `LateralSubquery` can refer up to attributes 
in the `LateralSubquery` or the containing query of the `LateralSubquery`.
   This is becuase when we're resolving a `LateralSubquery`, we update the 
`AnalysisContext.outerplans` to clear all the outerPlans before and only leaves 
the direct outerPlan for the `LateralSubquery`'s plan. This include any 
subqueries within the lateralSubquery.
   
   For other subqueries not within the `LateralSubquery` but are resolved after 
resolving `LateralSubquery`, we didn't change the AnalysisContext for them.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to