beliefer commented on code in PR #38461: URL: https://github.com/apache/spark/pull/38461#discussion_r1011086001
########## 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: @peter-toth 's suggestion could keep the readability and simplify code too. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org