pratham76 commented on code in PR #58656:
URL: https://github.com/apache/spark/pull/58656#discussion_r4356981733


##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RewriteSubquerySuite.scala:
##########
@@ -161,4 +163,124 @@ class RewriteSubquerySuite extends PlanTest {
     val existsExpected = LocalRelation(existsQuery.analyze.output).analyze
     comparePlans(existsOptimized, existsExpected)
   }
+
+  test("SPARK-59351: nested subquery of an EXISTS whose plan shares attributes 
with the outer " +
+    "plan") {
+    // The EXISTS arms route the nested subquery against the raw subquery 
plan, while the IN arms
+    // route it against the plan dedupSubqueryOnSelfJoin has already separated 
from the outer
+    // plan. A self-join can leave an ExprId shared between the two plans for 
the optimizer
+    // (SPARK-21835), and the analyzer is not involved here, so build that 
state directly: `a` is
+    // the same attribute in the outer and in the subquery plan.
+    val a = $"a".int
+    val outer = LocalRelation(a, $"b".int)
+    val sub = LocalRelation(a)
+    val nested = LocalRelation($"col1".int)
+    assert(outer.outputSet.intersect(sub.outputSet).nonEmpty,
+      "the two plans must share an attribute for this test to mean anything")
+
+    // The nested subquery references `a`, which only the subquery plan is 
meant to give it, and
+    // is correlated to it, so it must be rewritten against the subquery plan. 
Classifying `a` as

Review Comment:
   Fixed, and apologies -- last round I aligned the paragraph below this one 
and left this sentence, which is why the thread had to be reopened. It now 
states the swap and its outcome



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

Reply via email to