Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7458#discussion_r34880005
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate2/Aggregate2Sort.scala
 ---
    @@ -0,0 +1,365 @@
    +/*
    + * 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.aggregate2
    +
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.catalyst.InternalRow
    +import org.apache.spark.sql.catalyst.errors._
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.expressions.aggregate2._
    +import org.apache.spark.sql.catalyst.plans.physical.{AllTuples, 
ClusteredDistribution, Distribution, UnspecifiedDistribution}
    +import org.apache.spark.sql.execution.{SparkPlan, UnaryNode}
    +import org.apache.spark.sql.types.NullType
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +case class Aggregate2Sort(
    +    groupingExpressions: Seq[NamedExpression],
    +    aggregateExpressions: Seq[AggregateExpression2],
    +    aggregateAttributes: Seq[Attribute],
    +    resultExpressions: Seq[NamedExpression],
    +    child: SparkPlan)
    +  extends UnaryNode {
    +
    +  /** Indicates if this operator is for partial aggregations. */
    +  val partialAggregation: Boolean = {
    +    aggregateExpressions.map(_.mode).distinct.toList match {
    +      case Partial :: Nil => true
    +      case Final :: Nil => false
    +      case other =>
    +        sys.error(
    +          s"Could not evaluate ${aggregateExpressions} because we do not 
support evaluate " +
    +          s"modes $other in this operator.")
    +    }
    +  }
    +
    +  override def requiredChildDistribution: List[Distribution] = {
    +    if (partialAggregation) {
    +      UnspecifiedDistribution :: Nil
    +    } else {
    +      if (groupingExpressions == Nil) {
    +        AllTuples :: Nil
    +      } else {
    +        ClusteredDistribution(groupingExpressions) :: Nil
    +      }
    +    }
    +  }
    +
    +  override def requiredChildOrdering: Seq[Seq[SortOrder]] =
    +    groupingExpressions.map(SortOrder(_, Ascending)) :: Nil
    +
    +  override def output: Seq[Attribute] = 
resultExpressions.map(_.toAttribute)
    +
    +  protected override def doExecute(): RDD[InternalRow] = attachTree(this, 
"execute") {
    +    child.execute().mapPartitions { iter =>
    +
    +      new Iterator[InternalRow] {
    --- End diff --
    
    Probably we'd better split the partial / final aggregation Iterator into 
different class. As the partial aggregation(pre-shuffle) can be followed by 
hash/sort aggregation(post-shuffle) for the further improvement.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to