mgaido91 commented on a change in pull request #23531: [SPARK-24497][SQL]
Support recursive SQL query
URL: https://github.com/apache/spark/pull/23531#discussion_r250918583
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -205,33 +206,170 @@ class Analyzer(
CleanupAliases)
)
+ object ResolveRecursiveReferneces extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = {
+ val recursiveTables = plan.collect {
+ case rt @ RecursiveTable(name, _, _, _) if rt.anchorResolved => name
-> rt
+ }.toMap
+
+ plan.resolveOperatorsUp {
+ case UnresolvedRecursiveReference(name) if
recursiveTables.contains(name) =>
+ // creating new instance of attributes here makes possible to avoid
complex attribute
+ // handling in FoldablePropagation
+ RecursiveReference(name,
recursiveTables(name).output.map(_.newInstance()))
+ case other => other
+ }
+ }
+ }
+
/**
* Analyze cte definitions and substitute child plan with analyzed cte
definitions.
*/
object CTESubstitution extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp {
- case With(child, relations) =>
+ case With(child, relations, allowRecursion) =>
Review comment:
it is pretty hard to follow the code here, can we separate the handling of
the 2 cases,, ie.
```
case With(child, relations, false) => // leave it as before
case With(child, relations, true) => // do RecursiveReference resolution
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]