You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "Pajaraja (via GitHub)" <gi...@apache.org> on 2025/04/09 08:49:13 UTC

[PR] [SPARK-51751][SQL] Fix multiple rCTEs for one WITH statement that reference each other [spark]

Pajaraja opened a new pull request, #50544:
URL: https://github.com/apache/spark/pull/50544

   ### What changes were proposed in this pull request?
   
   Add a check to UnionLoopExec that the UnionLoopRef in its subtree is referring to the correct query. This is important since if we call another rCTE from it, it will also have a UnionLoopRef which needs to not be replaced with the reference.
   
   ### Why are the changes needed?
   
   Multiple rCTEs within one WITH statement ended in an infinite recursion.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   New golden file test added.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No.


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51751][SQL] Fix multiple rCTEs for one WITH statement that reference each other [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #50544:
URL: https://github.com/apache/spark/pull/50544#issuecomment-2791390649

   thanks, merging to master!


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51751][SQL] Fix multiple rCTEs for one WITH statement that reference each other [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #50544: [SPARK-51751][SQL] Fix multiple rCTEs for one WITH statement that reference each other
URL: https://github.com/apache/spark/pull/50544


-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51751][SQL] Fix multiple rCTEs for one WITH statement that reference each other [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #50544:
URL: https://github.com/apache/spark/pull/50544#discussion_r2035599845


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/UnionLoopExec.scala:
##########
@@ -188,7 +188,7 @@ case class UnionLoopExec(
         // This way we support only UNION ALL case. Additional case should be added for UNION case.
         // One way of supporting UNION case can be seen at SPARK-24497 PR from Peter Toth.
         val newRecursion = recursion.transform {
-          case r: UnionLoopRef =>
+          case r: UnionLoopRef if (r.loopId == loopId) =>

Review Comment:
   ```suggestion
             case r: UnionLoopRef if r.loopId == loopId =>
   ```



##########
sql/core/src/test/resources/sql-tests/inputs/cte-recursion.sql:
##########
@@ -486,4 +486,17 @@ WITH RECURSIVE
         UNION ALL
         SELECT t.id + 1, xid * 10 + x.id FROM t CROSS JOIN x WHERE t.id < 3
     )
-SELECT * FROM t
\ No newline at end of file
+SELECT * FROM t;
+
+-- rCTE referencing other rCTE
+    WITH RECURSIVE t1(a, b) AS (

Review Comment:
   ```suggestion
   WITH RECURSIVE t1(a, b) AS (
   ```



-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org