cloud-fan commented on code in PR #50904:
URL: https://github.com/apache/spark/pull/50904#discussion_r2093587305


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CTESubstitution.scala:
##########
@@ -65,19 +65,31 @@ object CTESubstitution extends Rule[LogicalPlan] {
       case p => p.children.flatMap(collectCommands)
     }
     val commands = collectCommands(plan)
+    val hasRecursiveCTE = plan.collectFirstWithSubqueries {
+      case UnresolvedWith(_, _, true) =>
+        true
+    }.getOrElse(false)
     val forceInline = if (commands.length == 1) {
       if (conf.getConf(SQLConf.LEGACY_INLINE_CTE_IN_COMMANDS)) {
         // The legacy behavior always inlines the CTE relations for queries in 
commands.
         true
       } else {
         // If there is only one command and it's `CTEInChildren`, we can 
resolve
         // CTE normally and don't need to force inline.
-        !commands.head.isInstanceOf[CTEInChildren]
+        if (hasRecursiveCTE) {
+          false
+        } else {
+          !commands.head.isInstanceOf[CTEInChildren]
+        }
       }
     } else if (commands.length > 1) {
       // This can happen with the multi-insert statement. We should fall back 
to
       // the legacy behavior.
-      true
+      if (hasRecursiveCTE) {

Review Comment:
   `!hasRecursiveCTE`



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

Reply via email to