cloud-fan commented on code in PR #50546: URL: https://github.com/apache/spark/pull/50546#discussion_r2039400525
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveWithCTE.scala: ########## @@ -83,8 +83,21 @@ object ResolveWithCTE extends Rule[LogicalPlan] { cteDef.copy(child = alias.copy(child = loop)) } + // Simple case of duplicating (UNION ALL) clause, with CTEs inside. + case alias @ SubqueryAlias(_, withCTE @ WithCTE( + Union(Seq(anchor, recursion), false, false), _)) => + if (!anchor.resolved) { + cteDef + } else { + val loop = UnionLoop( + cteDef.id, + anchor, + rewriteRecursiveCTERefs(recursion, anchor, cteDef.id, None)) + cteDef.copy(child = alias.copy(child = withCTE.copy(plan = loop))) + } + // The case of CTE name followed by a parenthesized list of column name(s), eg. - // WITH RECURSIVE t(n). + // WITH RECURSIVE t(n), with CTEs inside. Review Comment: ```suggestion // WITH RECURSIVE t(n). ``` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org