maropu commented on a change in pull request #29585:
URL: https://github.com/apache/spark/pull/29585#discussion_r490216289
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala
##########
@@ -510,16 +514,16 @@ object RewriteCorrelatedScalarSubquery extends
Rule[LogicalPlan] {
*/
private def constructLeftJoins(
child: LogicalPlan,
- subqueries: ArrayBuffer[ScalarSubquery]): LogicalPlan = {
+ subqueries: ArrayBuffer[(ScalarSubquery, ExprId)]): LogicalPlan = {
subqueries.foldLeft(child) {
- case (currentChild, ScalarSubquery(query, conditions, _)) =>
+ case (currentChild, (ScalarSubquery(query, conditions, _), newExprId)) =>
val origOutput = query.output.head
val resultWithZeroTups = evalSubqueryOnZeroTups(query)
if (resultWithZeroTups.isEmpty) {
// CASE 1: Subquery guaranteed not to have the COUNT bug
Project(
- currentChild.output :+ origOutput,
+ currentChild.output :+ Alias(origOutput, origOutput.name)(exprId =
newExprId),
Review comment:
Rewritten expressions in a parent node, `Aggregate` or `Project`, need
to refer to an attribute with `newExprId` in this child `Project`. The
rewritten exprs are generated in `extractCorrelatedScalarSubqueries`:
https://github.com/apache/spark/pull/29585/files#diff-597bd2d5f41c767bfbca973b9c0c4766R343-R353
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]