Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8874#discussion_r40239061
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/utils.scala ---
    @@ -37,6 +37,57 @@ object Utils {
           UnsafeProjection.canSupport(groupingExpressions)
       }
     
    +  def planAggregateWithoutPartial(
    +      groupingExpressions: Seq[Expression],
    +      aggregateExpressions: Seq[AggregateExpression2],
    +      aggregateFunctionMap: Map[(AggregateFunction2, Boolean), 
(AggregateFunction2, Attribute)],
    +      resultExpressions: Seq[NamedExpression],
    +      child: SparkPlan): Seq[SparkPlan] = {
    +
    +    val namedGroupingExpressions = groupingExpressions.map {
    +      case ne: NamedExpression => ne -> ne
    +      // If the expression is not a NamedExpressions, we add an alias.
    +      // So, when we generate the result of the operator, the Aggregate 
Operator
    +      // can directly get the Seq of attributes representing the grouping 
expressions.
    +      case other =>
    +        val withAlias = Alias(other, other.toString)()
    +        other -> withAlias
    +    }
    +    val groupExpressionMap = namedGroupingExpressions.toMap
    +    val namedGroupingAttributes = 
namedGroupingExpressions.map(_._2.toAttribute)
    +
    +    val finalAggregateExpressions = aggregateExpressions.map(_.copy(mode = 
Complete))
    +    val finalAggregateAttributes =
    +      finalAggregateExpressions.map {
    +        expr => aggregateFunctionMap(expr.aggregateFunction, 
expr.isDistinct)._2
    +      }
    +
    +    val rewrittenResultExpressions = resultExpressions.map { expr =>
    +      expr.transformDown {
    +        case agg: AggregateExpression2 =>
    +          aggregateFunctionMap(agg.aggregateFunction, agg.isDistinct)._2
    --- End diff --
    
    Do we need to use the following instead?
    ```
    // aggregateFunctionMap contains unique aggregate functions.
    val aggregateFunction =
      aggregateFunctionMap(agg.aggregateFunction, agg.isDistinct)._1
      aggregateFunction.asInstanceOf[AlgebraicAggregate].evaluateExpression
    ```
    Basically `rewrittenResultExpressions` will do the work of evaluating 
aggregate functions and generate final results.


---
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