dtenedor commented on code in PR #37840:
URL: https://github.com/apache/spark/pull/37840#discussion_r971116242


##########
sql/core/src/test/resources/sql-tests/results/subquery/negative-cases/invalid-correlation.sql.out:
##########
@@ -105,14 +131,20 @@ WHERE  t1a IN (SELECT t2a
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-Expressions referencing the outer query are not supported outside of 
WHERE/HAVING clauses:
-Aggregate [min(outer(t2a#x)) AS min(outer(t2.t2a))#x]
-+- SubqueryAlias t3
-   +- View (`t3`, [t3a#x,t3b#x,t3c#x])
-      +- Project [cast(t3a#x as int) AS t3a#x, cast(t3b#x as int) AS t3b#x, 
cast(t3c#x as int) AS t3c#x]
-         +- Project [t3a#x, t3b#x, t3c#x]
-            +- SubqueryAlias t3
-               +- LocalRelation [t3a#x, t3b#x, t3c#x]
+{
+  "errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY",
+  "errorSubClass" : "UNSUPPORTED_CORRELATED_REFERENCE",
+  "messageParameters" : {
+    "planString" : ": Aggregate [min(outer(t2a#6)) AS 
min(outer(t2.t2a))#7]\n+- SubqueryAlias t3\n   +- View (`t3`, 
[t3a#3,t3b#4,t3c#5])\n      +- Project [cast(t3a#0 as int) AS t3a#3, cast(t3b#1 
as int) AS t3b#4, cast(t3c#2 as int) AS t3c#5]\n         +- Project [t3a#0, 
t3b#1, t3c#2]\n            +- SubqueryAlias t3\n               +- LocalRelation 
[t3a#0, t3b#1, t3c#2]\n"

Review Comment:
   Good Q. I found they are not stable when running the tests outside of my 
local machine, therefore to prevent the tests from becoming flaky, I found it 
necessary to normalize the expression IDs. I added code in the `failAnalysis` 
overload that takes `TreeNode`s to do that, iterating through the trees to 
reset the expression IDs. This should be more robust than regex-replacing the 
string. We do have the existing `canonicalized` method on logical plans and 
expressions, but that uses `transformUp` which is not allowed in the analyzer, 
so I ended up doing it separately here for this purpose.



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