-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-12978][SQL] Skip unnecessary final group-by when input data al…
…ready clustered with group-by keys This ticket targets the optimization to skip an unnecessary group-by operation below; Without opt.: ``` == Physical Plan == TungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Final,isDistinct=false),(avg(col2#161),mode=Final,isDistinct=false)], output=[col0#159,sum(col1)#177,avg(col2)#178]) +- TungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Partial,isDistinct=false),(avg(col2#161),mode=Partial,isDistinct=false)], output=[col0#159,sum#200,sum#201,count#202L]) +- TungstenExchange hashpartitioning(col0#159,200), None +- InMemoryColumnarTableScan [col0#159,col1#160,col2#161], InMemoryRelation [col0#159,col1#160,col2#161], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, None ``` With opt.: ``` == Physical Plan == TungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Complete,isDistinct=false),(avg(col2#161),mode=Final,isDistinct=false)], output=[col0#159,sum(col1)#177,avg(col2)#178]) +- TungstenExchange hashpartitioning(col0#159,200), None +- InMemoryColumnarTableScan [col0#159,col1#160,col2#161], InMemoryRelation [col0#159,col1#160,col2#161], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, None ``` Author: Takeshi YAMAMURO <[email protected]> Closes #10896 from maropu/SkipGroupbySpike.
- Loading branch information
1 parent
6b8cb1f
commit 2b0cc4e
Showing
8 changed files
with
257 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 115 additions & 135 deletions
250
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggUtils.scala
Large diffs are not rendered by default.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggregateExec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.spark.sql.execution.aggregate | ||
|
||
import org.apache.spark.sql.catalyst.expressions._ | ||
import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
import org.apache.spark.sql.catalyst.plans.physical._ | ||
import org.apache.spark.sql.execution.SparkPlan | ||
import org.apache.spark.sql.execution.UnaryExecNode | ||
|
||
/** | ||
* A base class for aggregate implementation. | ||
*/ | ||
abstract class AggregateExec extends UnaryExecNode { | ||
|
||
def requiredChildDistributionExpressions: Option[Seq[Expression]] | ||
def groupingExpressions: Seq[NamedExpression] | ||
def aggregateExpressions: Seq[AggregateExpression] | ||
def aggregateAttributes: Seq[Attribute] | ||
def initialInputBufferOffset: Int | ||
def resultExpressions: Seq[NamedExpression] | ||
|
||
protected[this] val aggregateBufferAttributes = { | ||
aggregateExpressions.flatMap(_.aggregateFunction.aggBufferAttributes) | ||
} | ||
|
||
override def producedAttributes: AttributeSet = | ||
AttributeSet(aggregateAttributes) ++ | ||
AttributeSet(resultExpressions.diff(groupingExpressions).map(_.toAttribute)) ++ | ||
AttributeSet(aggregateBufferAttributes) | ||
|
||
override def output: Seq[Attribute] = resultExpressions.map(_.toAttribute) | ||
|
||
override def requiredChildDistribution: List[Distribution] = { | ||
requiredChildDistributionExpressions match { | ||
case Some(exprs) if exprs.isEmpty => AllTuples :: Nil | ||
case Some(exprs) if exprs.nonEmpty => ClusteredDistribution(exprs) :: Nil | ||
case None => UnspecifiedDistribution :: Nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters