sigmod edited a comment on pull request #32298:
URL: https://github.com/apache/spark/pull/32298#issuecomment-1075406139


   One high level comment. 
   
   Does it make sense to implement the rewrite in the following way?
   
   ```
   SELECT
     (SELECT avg(a) FROM t GROUP BY b),
     (SELECT sum(b) FROM t GROUP BY b)
   FROM T
   ```
   
   =>
   ```
   WITH cte AS (SELECT avg(a) a, sum(b) b FROM t GROUP BY b)
   SELECT (SELECT a FROM cte), (SELECT b FROM cte)
   FROM T
   ```
   
   Since we already have 
[WithCTE](https://github.com/apache/spark/blob/efe43306fcab18f076f755c81c0406ebc1a5fee9/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala#L703-L710)
 and 
[CTERelationRef](https://github.com/apache/spark/blob/efe43306fcab18f076f755c81c0406ebc1a5fee9/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala#L678-L686),
 the rewrite looks similar to what you want to achieve, while do not need to 
add yet-another Logical/Exec node? 


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