cloud-fan commented on code in PR #50546: URL: https://github.com/apache/spark/pull/50546#discussion_r2039396283
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CTESubstitution.scala: ########## @@ -220,18 +224,31 @@ object CTESubstitution extends Rule[LogicalPlan] { errorClass = "RECURSIVE_CTE_WHEN_INLINING_IS_FORCED", messageParameters = Map.empty) } - val resolvedCTERelations = + + val tempCteDefs = ArrayBuffer.empty[CTERelationDef] + val resolvedCTERelations = if (recursiveCTERelationAncestor.isDefined) { + resolveCTERelations(relations, isLegacy = false, forceInline, outerCTEDefs, tempCteDefs, + recursiveCTERelationAncestor, allowRecursion) ++ outerCTEDefs + } else { resolveCTERelations(relations, isLegacy = false, forceInline, outerCTEDefs, cteDefs, - allowRecursion) ++ outerCTEDefs + recursiveCTERelationAncestor, allowRecursion) ++ outerCTEDefs + } val substituted = substituteCTE( - traverseAndSubstituteCTE(child, forceInline, resolvedCTERelations, cteDefs)._1, + traverseAndSubstituteCTE(child, forceInline, resolvedCTERelations, cteDefs, + recursiveCTERelationAncestor)._1, + // If we are resolving CTEs in a recursive CTE, we need to inline it in case the Review Comment: but we can't inline if the inner CTE is also recursive, right? -- 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