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

    https://github.com/apache/spark/pull/9038#discussion_r41705892
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TungstenAggregationIterator.scala
 ---
    @@ -134,19 +137,74 @@ class TungstenAggregationIterator(
           completeAggregateExpressions.map(_.mode).distinct.headOption
       }
     
    -  // All aggregate functions. TungstenAggregationIterator only handles 
expression-based aggregate.
    -  // If there is any functions that is an ImperativeAggregateFunction, we 
throw an
    -  // IllegalStateException.
    -  private[this] val allAggregateFunctions: Array[DeclarativeAggregate] = {
    -    if (!allAggregateExpressions.forall(
    -        _.aggregateFunction.isInstanceOf[DeclarativeAggregate])) {
    -      throw new IllegalStateException(
    -        "Only ExpressionAggregateFunctions should be passed in 
TungstenAggregationIterator.")
    +  // Initialize all AggregateFunctions by binding references, if necessary,
    +  // and setting inputBufferOffset and mutableBufferOffset.
    +  private def initializeAllAggregateFunctions(
    +      startingInputBufferOffset: Int): Array[AggregateFunction2] = {
    +    var mutableBufferOffset = 0
    +    var inputBufferOffset: Int = startingInputBufferOffset
    +    val functions = new 
Array[AggregateFunction2](allAggregateExpressions.length)
    +    var i = 0
    +    while (i < allAggregateExpressions.length) {
    +      val func = allAggregateExpressions(i).aggregateFunction
    --- End diff --
    
    Good catch! I wonder whether we can address this treating 
ImperativeAggregtate instances as immutable and changing the `with*Offset` 
methods to return new instances. This seems a bit easier / safer than having to 
remember to clone.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to