Github user lamuguo commented on a diff in the pull request: https://github.com/apache/spark/pull/867#discussion_r13217800 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/Aggregate.scala --- @@ -155,48 +155,60 @@ case class Aggregate( } } else { child.execute().mapPartitions { iter => - val hashTable = new HashMap[Row, Array[AggregateFunction]] - val groupingProjection = new MutableProjection(groupingExpressions, childOutput) - - var currentRow: Row = null - while (iter.hasNext) { - currentRow = iter.next() - val currentGroup = groupingProjection(currentRow) - var currentBuffer = hashTable.get(currentGroup) - if (currentBuffer == null) { - currentBuffer = newAggregateBuffer() - hashTable.put(currentGroup.copy(), currentBuffer) + val groupingProjection = new + MutableProjection(groupingExpressions, childOutput) + // TODO: Can't use "Array[AggregateFunction]" directly, due to lack of + // "concat(AggregateFunction, AggregateFunction)". Should add + // AggregateFunction.update(agg: AggregateFunction) in the future. + def createCombiner(row: Row) = mergeValue(newAggregateBuffer(), row) + def mergeValue(buffer: Array[AggregateFunction], row: Row) = { + for (i <- 0 to buffer.length - 1) { + buffer(i).update(row) } - - var i = 0 - while (i < currentBuffer.length) { - currentBuffer(i).update(currentRow) - i += 1 + buffer + } + def mergeCombiners(buf1: Array[AggregateFunction], buf2: Array[AggregateFunction]) = { + if (buf1.length != buf2.length) { + throw new TreeNodeException(this, s"Unequal aggregate buffer length ${buf1.length} != ${buf2.length}") + } + for (i <- 0 to buf1.length - 1) { --- End diff -- Done
--- 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. ---