peter-toth commented on pull request #32298:
URL: https://github.com/apache/spark/pull/32298#issuecomment-1076546385


   @sigmod, how about doing this kind of transformation?
   
   ```
   SELECT
     (SELECT avg(a) FROM t GROUP BY b),
     (SELECT sum(b) FROM t GROUP BY b)
   FROM T
   ```
   => 
   ```
   WITH cte AS (SELECT named_struct(a, avg(a), b, sum(b)) mergedValue FROM t 
GROUP BY b)
   SELECT (SELECT mergedValue FROM cte).a, (SELECT mergedValue FROM cte).b
   FROM T
   ```
   and adding a flag to `cte` `CTERelationDef` that it hosts a scalar query + 
changing `WithCTEStrategy` a bit to avoid extra shuffles in those cases as 
`ReuseExchangeAndSubquery` can insert `ReusedSubqueryExec` nodes (no need to 
insert  `ReusedExchangeExec`). 


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