You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-50739][SQL] Recursive CTE. Analyzer changes to unravel and resolve the recursion components
### What changes were proposed in this pull request?
Instruction for reviewers https://docs.google.com/document/d/1qcEJxqoXcr5cSt6HgIQjWQSqhfkSaVYkoDHsg5oxXp4/edit
Introduction of UnionLoop and UnionLoopRef logical plan classes. Changes in ResolveWithCTE.scala to have the analyzer grok recursive anchors. Specifically we substitute CTERelationRef with UnionLoopRef, and Union with UnionLoop. We untangle the dead loop in resolving where recursive CTE reference is referring to an unresolved CTE definition, which itself cannot be resolved as one of its descendants is an unresolved CTE reference.
### Why are the changes needed?
Support for the recursive CTE.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Proposed changes in this PR are no-op. Tested
./build/sbt "test:testOnly org.apache.spark.sql.SQLQueryTestSuite"
./build/sbt "test:testOnly *PlanParserSuite"
### Was this patch authored or co-authored using generative AI tooling?
No
Closes#49351 from nemanjapetr-db/nemanjapetr-db/rcte3.
Authored-by: Nemanja Petrovic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
Copy file name to clipboardExpand all lines: common/utils/src/main/resources/error/error-conditions.json
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3105,6 +3105,12 @@
3105
3105
],
3106
3106
"sqlState" : "42613"
3107
3107
},
3108
+
"INVALID_RECURSIVE_CTE" : {
3109
+
"message" : [
3110
+
"Invalid recursive definition found. Recursive queries must contain an UNION or an UNION ALL statement with 2 children. The first child needs to be the anchor term without any recursive references."
3111
+
],
3112
+
"sqlState" : "42836"
3113
+
},
3108
3114
"INVALID_REGEXP_REPLACE" : {
3109
3115
"message" : [
3110
3116
"Could not perform regexp_replace for source = \"<source>\", pattern = \"<pattern>\", replacement = \"<replacement>\" and position = <position>."
Copy file name to clipboardExpand all lines: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PushdownPredicatesAndPruneColumnsForCTEDef.scala
0 commit comments