jackylee-ch commented on code in PR #12052: URL: https://github.com/apache/gluten/pull/12052#discussion_r3206750848
########## gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushPartialAggThroughExpand.scala: ########## @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gluten.extension.columnar + +import org.apache.gluten.config.GlutenConfig + +import org.apache.spark.internal.Logging +import org.apache.spark.sql.catalyst.expressions._ +import org.apache.spark.sql.catalyst.expressions.aggregate._ +import org.apache.spark.sql.catalyst.rules.Rule +import org.apache.spark.sql.execution.{ExpandExec, SparkPlan} +import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanExec +import org.apache.spark.sql.execution.aggregate.HashAggregateExec + +/** + * Physical plan rule that pushes a partial [[HashAggregateExec]] through an [[ExpandExec]] so that + * pre-aggregation happens on the original (un-expanded) rows. + * + * Actual Q67 physical plan produced by Spark: + * + * HashAggregateExec (final) Exchange (shuffle by [grouping_keys..., spark_grouping_id]) + * HashAggregateExec (partial) <-- sees 9x expanded rows ExpandExec (9 projections for ROLLUP) + * Project BroadcastHashJoin ... + * + * After this rule: + * + * HashAggregateExec (final) Exchange HashAggregateExec (partial-merge) <-- merges per + * (grouping_keys, gid) ExpandExec (augmented) <-- pass-through + null-fill HashAggregateExec + * (partial) <-- pre-agg on original rows, no gid Project BroadcastHashJoin ... + */ +object PushPartialAggThroughExpand extends Rule[SparkPlan] with Logging { Review Comment: This seems useful for vanilla Spark as well? Should we consider merging it into the upstream Spark? -- 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]
