milanisvet commented on code in PR #49232:
URL: https://github.com/apache/spark/pull/49232#discussion_r1898006388
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CTESubstitution.scala:
##########
@@ -247,58 +259,137 @@ object CTESubstitution extends Rule[LogicalPlan] {
// NOTE: we must call `traverseAndSubstituteCTE` before
`substituteCTE`, as the relations
// in the inner CTE have higher priority over the relations in the
outer CTE when resolving
// inner CTE relations. For example:
- // WITH t1 AS (SELECT 1)
- // t2 AS (
- // WITH t1 AS (SELECT 2)
- // WITH t3 AS (SELECT * FROM t1)
- // )
+ // WITH
+ // t1 AS (SELECT 1),
+ // t2 AS (
+ // WITH
+ // t1 AS (SELECT 2),
+ // t3 AS (SELECT * FROM t1)
+ // SELECT * FROM t1
+ // )
+ // SELECT * FROM t2
// t3 should resolve the t1 to `SELECT 2` instead of `SELECT 1`.
- traverseAndSubstituteCTE(relation, forceInline, resolvedCTERelations,
cteDefs)._1
+ //
+ // When recursion allowed:
+ // - don't add current definition to outer definitions of
`traverseAndSubstituteCTE()` to
+ // prevent recursion inside inner CTEs.
+ // E.g. the following query will not resolve `t1` within `t2`:
Review Comment:
Modified comments. Will resolve this comment and leave the following one
--
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]