pan3793 commented on code in PR #58661:
URL: https://github.com/apache/spark/pull/58661#discussion_r3976569923


##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -9090,6 +9090,11 @@
           "Literal for '<value>' of <type>."
         ]
       },
+      "MATERIALIZED_CTE_WITH_OUTER_REFERENCE" : {

Review Comment:
   Left unchanged: with the boundary fix, `<colName>` always names a column 
defined outside the CTE.



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala:
##########
@@ -1330,6 +1331,35 @@ class AnalysisErrorSuite extends AnalysisTest with 
DataTypeErrorsBase {
       "expr" -> "\"_w0\"",
       "exprType" -> "\"MAP<STRING, STRING>\""))
 
+  test("MATERIALIZED CTE cannot reference the outer query") {
+    val relation = LocalRelation($"a".int)
+    def cteRef(cteDef: CTERelationDef): CTERelationRef = {
+      CTERelationRef(cteDef.id, cteDef.resolved, cteDef.output, 
cteDef.isStreaming)
+    }
+    def assertMaterializedCTEError(
+        cteChild: LogicalPlan,
+        colName: String,
+        referencedCTEDefs: Seq[CTERelationDef] = Nil): Unit = {
+      val cteDef = CTERelationDef(cteChild, materialized = Some(true))
+      val plan = WithCTE(cteRef(cteDef).select(colName), referencedCTEDefs :+ 
cteDef)
+      checkError(
+        exception = 
intercept[AnalysisException](getAnalyzer.checkAnalysis(plan)),
+        condition = 
"UNSUPPORTED_FEATURE.MATERIALIZED_CTE_WITH_OUTER_REFERENCE",
+        parameters = Map("colName" -> "`a`"))

Review Comment:
   Fixed in 7e742bb73a4: the helper takes the expected outer column explicitly.



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