peter-toth commented on code in PR #38461:
URL: https://github.com/apache/spark/pull/38461#discussion_r1010548429
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/MergeScalarSubqueries.scala:
##########
@@ -346,25 +346,19 @@ object MergeScalarSubqueries extends Rule[LogicalPlan] {
// Only allow aggregates of the same implementation because merging
different implementations
// could cause performance regression.
private def supportedAggregateMerge(newPlan: Aggregate, cachedPlan:
Aggregate) = {
- val newPlanAggregateExpressions =
newPlan.aggregateExpressions.flatMap(_.collect {
- case a: AggregateExpression => a
- })
- val cachedPlanAggregateExpressions =
cachedPlan.aggregateExpressions.flatMap(_.collect {
- case a: AggregateExpression => a
- })
- val newPlanSupportsHashAggregate = Aggregate.supportsHashAggregate(
-
newPlanAggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes))
- val cachedPlanSupportsHashAggregate = Aggregate.supportsHashAggregate(
-
cachedPlanAggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes))
- newPlanSupportsHashAggregate && cachedPlanSupportsHashAggregate ||
- newPlanSupportsHashAggregate == cachedPlanSupportsHashAggregate && {
- val newPlanSupportsObjectHashAggregate =
- Aggregate.supportsObjectHashAggregate(newPlanAggregateExpressions)
- val cachedPlanSupportsObjectHashAggregate =
- Aggregate.supportsObjectHashAggregate(cachedPlanAggregateExpressions)
- newPlanSupportsObjectHashAggregate &&
cachedPlanSupportsObjectHashAggregate ||
- newPlanSupportsObjectHashAggregate ==
cachedPlanSupportsObjectHashAggregate
- }
+ val aggregateExprSeq =
+ Seq(newPlan, cachedPlan).map(plan =>
plan.aggregateExpressions.flatMap(_.collect {
+ case a: AggregateExpression => a
+ }))
+ val supportsHashAggregates = aggregateExprSeq.map(aggregateExpressions =>
Review Comment:
Thanks @beliefer for the PR. I'm ok with the changes. Only a nit that you
could probably use `val Seq(newPlanSupportsHashAggregates,
cachedPlanSupportsHashAggregates) = ...` syntax here to avoid using `.head` and
`.last`.
--
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]