AngersZhuuuu commented on code in PR #44767:
URL: https://github.com/apache/spark/pull/44767#discussion_r1463025288


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -910,6 +910,30 @@ case class WithCTE(plan: LogicalPlan, cteDefs: 
Seq[CTERelationDef]) extends Logi
   def withNewPlan(newPlan: LogicalPlan): WithCTE = {
     withNewChildren(children.init :+ newPlan).asInstanceOf[WithCTE]
   }
+
+  override def doCanonicalize(): LogicalPlan = {
+    val canonicalized = super.doCanonicalize().asInstanceOf[WithCTE]
+    val defIndex = canonicalized.cteDefs.map(_.id).zipWithIndex.toMap
+
+    def canonicalizeCTE(plan: LogicalPlan): LogicalPlan = {
+      plan.resolveOperatorsUpWithPruning(
+        _.containsAnyPattern(CTE, PLAN_EXPRESSION)) {
+        case ref: CTERelationRef =>
+          ref.copy(cteId = defIndex(ref.cteId).toLong)
+

Review Comment:
   @cloud-fan Found nested WithCTE case, added to `cte.sql` and here change the 
method to support nested CTE, pls take a look again.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to