peter-toth commented on a change in pull request #23531: [SPARK-24497][SQL] 
Support recursive SQL query
URL: https://github.com/apache/spark/pull/23531#discussion_r250978228
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
 ##########
 @@ -144,6 +146,21 @@ abstract class LogicalPlan
       case (a1, a2) => a1.semanticEquals(a2)
     }
   }
+
+  /**
+   * If a plan contains a RecursiveReference without an enclosing 
RecursiveTable than it means an
 
 Review comment:
   Thanks, indeed this needs some improvement.
   The reason I introduced this is this test case:
   ```
   WITH RECURSIVE t AS (
     VALUES(1, ARRAY_REMOVE(ARRAY(0), 0)) AS t(id, path)
     UNION ALL
     SELECT tree.id, t.path || ARRAY(tree.id)
     FROM tree
     JOIN t ON tree.parent_id = t.id
   )
   SELECT t1.id, t2.path, STRUCT(t2.*)
   FROM t AS t1
   JOIN t AS t2 ON t1.id = t2.id
   ```
   where the spark plan would be without this change:
   ```
   CollectLimit 101
   +- *(6) Project [cast(id#332 as string) AS id#349, cast(path#341 as string) 
AS path#350, cast(named_struct(id, id#340, path, path#341) as string) AS 
named_struct(id, id, path, path)#351]
      +- *(6) BroadcastHashJoin [id#332], [id#340], Inner, BuildLeft
         :- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, 
int, true] as bigint)))
         :  +- *(3) Project [id#332]
         :     +- *(3) Filter isnotnull(id#332)
         :        +- RecursiveTable t
         :           :- LocalTableScan [id#332, path#333]
         :           +- *(2) Project [id#274, concat(path#335, array(id#274)) 
AS concat(path, array(id))#338]
         :              +- *(2) BroadcastHashJoin [parent_id#275], [id#334], 
Inner, BuildRight
         :                 :- *(2) Project [_1#269 AS id#274, _2#270 AS 
parent_id#275]
         :                 :  +- *(2) Filter isnotnull(_2#270)
         :                 :     +- LocalTableScan [_1#269, _2#270]
         :                 +- BroadcastExchange 
HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)))
         :                    +- *(1) Filter isnotnull(id#334)
         :                       +- RecursiveReference t, [id#334, path#335]
         +- *(6) Filter isnotnull(id#340)
            +- RecursiveTable t
               :- LocalTableScan [id#340, path#341]
               +- *(5) Project [id#274, concat(path#337, array(id#274)) AS 
concat(path, array(id))#339]
                  +- *(5) BroadcastHashJoin [parent_id#275], [id#336], Inner, 
BuildRight
                     :- *(5) Project [_1#269 AS id#274, _2#270 AS parent_id#275]
                     :  +- *(5) Filter isnotnull(_2#270)
                     :     +- LocalTableScan [_1#269, _2#270]
                     +- ReusedExchange [id#336, path#337], BroadcastExchange 
HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)))
   ```
   Here the `ReusedExchange` should'n be there because it refers to a 
`RecursiveReference` without an enclosing `RecursiveTable` and so it means 
different result depending on where the exchange is used.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to