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-50838][SQL] Performs additional checks inside recursive CTEs to throw an error if forbidden case is encountered
### What changes were proposed in this pull request?
Performs additional checks inside recursive CTEs to throw an error if forbidden case is encountered:
1. Recursive term can contain one recursive reference only.
2. Recursive reference can't be used in some kinds of joins and aggregations.
3. Recursive references are not allowed in subqueries
In addition, the name of `recursive` function inside `CTERelationDef` is rewritten to `hasRecursiveCTERelationRef` and adds `hasItsOwnUnionLoopRef` function as it is also needed to check if cteDef is recursive after substitution.
A small bug in `CTESubstitution` is fixed which now enables substitution of self-references within subqueries as well (but not its resolution, as they are not allowed).
### Why are the changes needed?
Support for the recursive CTE.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
will be tested in #49571
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes#49518 from milanisvet/checkRecursion.
Authored-by: Milan Cupac <[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
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3135,6 +3135,24 @@
3135
3135
],
3136
3136
"sqlState" : "42836"
3137
3137
},
3138
+
"INVALID_RECURSIVE_REFERENCE" : {
3139
+
"message" : [
3140
+
"Invalid recursive reference found inside WITH RECURSIVE clause."
3141
+
],
3142
+
"subClass" : {
3143
+
"NUMBER" : {
3144
+
"message" : [
3145
+
"Multiple self-references to one recursive CTE are not allowed."
3146
+
]
3147
+
},
3148
+
"PLACE" : {
3149
+
"message" : [
3150
+
"Recursive references cannot be used on the right side of left outer/semi/anti joins, on the left side of right outer joins, in full outer joins, in aggregates, and in subquery expressions."
3151
+
]
3152
+
}
3153
+
},
3154
+
"sqlState" : "42836"
3155
+
},
3138
3156
"INVALID_REGEXP_REPLACE" : {
3139
3157
"message" : [
3140
3158
"Could not perform regexp_replace for source = \"<source>\", pattern = \"<pattern>\", replacement = \"<replacement>\" and position = <position>."
0 commit comments