cloud-fan commented on a change in pull request #33990:
URL: https://github.com/apache/spark/pull/33990#discussion_r713588561
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -982,6 +983,17 @@ object CollapseProject extends Rule[LogicalPlan] with
AliasHelper {
case _ => false
}
+ /**
+ * Check if the Project can be combined with the aggregate. If there exists
a correlated
+ * scalar subquery in the project list that uses the output of the
aggregate, the project
+ * cannot be collapsed. Otherwise the plan after subquery rewrite will not
be valid.
+ */
+ private def canCollapseAggregate(p: Project, a: Aggregate): Boolean = {
+ p.projectList.forall(_.collect {
+ case s: ScalarSubquery if
AttributeSet(s.children).intersect(a.outputSet).nonEmpty => s
Review comment:
We should only check if `outerAttrs.nonEmpty`
--
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]