beliefer commented on code in PR #43614:
URL: https://github.com/apache/spark/pull/43614#discussion_r1378685716


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala:
##########
@@ -120,6 +120,30 @@ case class InlineCTE(alwaysInline: Boolean = false) 
extends Rule[LogicalPlan] {
           }
         }
     }
+    // If a CTE ref count is 0, the other CTE that is referencing it should 
also have
+    // a 0 ref count.
+    val visited: mutable.Map[Long, Boolean] = 
mutable.Map.empty.withDefaultValue(false)
+    cteMap.foreach { case(cteId, _) =>

Review Comment:
   ```suggestion
       cteMap.foreach { case (cteId, (_, refCount, _)) =>
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/InlineCTE.scala:
##########
@@ -120,6 +120,30 @@ case class InlineCTE(alwaysInline: Boolean = false) 
extends Rule[LogicalPlan] {
           }
         }
     }
+    // If a CTE ref count is 0, the other CTE that is referencing it should 
also have
+    // a 0 ref count.
+    val visited: mutable.Map[Long, Boolean] = 
mutable.Map.empty.withDefaultValue(false)
+    cteMap.foreach { case(cteId, _) =>
+      val (_, refCount, _) = cteMap(cteId)
+      if (refCount == 0 && !visited(cteId) ) {
+        reconcileCTERefCount(cteMap, visited, cteId)

Review Comment:
   It seems we should inline `reconcileCTERefCount` here.



-- 
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