jchen5 commented on code in PR #40811:
URL: https://github.com/apache/spark/pull/40811#discussion_r1170166990
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/subquery.scala:
##########
@@ -325,9 +327,20 @@ object PullupCorrelatedPredicates extends
Rule[LogicalPlan] with PredicateHelper
}
plan.transformExpressionsWithPruning(_.containsPattern(PLAN_EXPRESSION)) {
- case ScalarSubquery(sub, children, exprId, conditions, hint) if
children.nonEmpty =>
+ case ScalarSubquery(sub, children, exprId, conditions, hint,
mayHaveCountBugOld)
+ if children.nonEmpty =>
val (newPlan, newCond) = decorrelate(sub, plan)
- ScalarSubquery(newPlan, children, exprId, getJoinCondition(newCond,
conditions), hint)
+ val mayHaveCountBug = if (mayHaveCountBugOld.isDefined) {
+ // For idempotency, we must save this variable the first time this
rule is run. Afterward,
+ // the information about whether the subquery has a GROUP BY clause
is lost because a
+ // GROUP BY is introduced if one wasn't already present.
Review Comment:
@cloud-fan In both code paths, we add GROUP BY on the correlating outer
columns in order to decorrelate the subquery.
In both DecorrelateInnerQuery and in pullOutCorrelatedPredicates it's under
`case a @ Aggregate`.
@viirya The value of mayHaveCountBug is based on the plan before
decorrelation, so it reflects whether it originally had group by or not. If the
GROUP BY is introduced by subquery decorrelation (in this rule) and it wasn't
there before, the value will be true, and if the GROUP BY was already there,
the value will be false.
--
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]