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


##########
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) {

Review Comment:
   `!hasRecursiveCTE && !commands.head.isInstanceOf[CTEInChildren]`



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