ulysses-you commented on code in PR #40915:
URL: https://github.com/apache/spark/pull/40915#discussion_r1177572665


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/ObjectAggregationIterator.scala:
##########
@@ -268,20 +281,24 @@ class SortBasedAggregator(
         if (hasNextInput || hasNextAggBuffer) {
           // Find smaller key of the initialAggBufferIterator and 
initialAggBufferIterator
           groupingKey = findGroupingKey()
-          result = new AggregationBufferEntry(groupingKey, 
makeEmptyAggregationBuffer)
+          initializeBuffer(sortBasedAggregationBuffer)
+          result = new AggregationBufferEntry(groupingKey, 
sortBasedAggregationBuffer)
 
           // Firstly, update the aggregation buffer with input rows.
-          while (hasNextInput &&
-            groupingKeyOrdering.compare(inputIterator.getKey, groupingKey) == 
0) {
-            processRow(result.aggregationBuffer, inputIterator.getValue)
-            hasNextInput = inputIterator.next()
+          if (aggregateMode != 1) {
+            var findNextPartition = false
+            while (hasNextInput && !findNextPartition) {
+              processRow(result.aggregationBuffer, inputIterator.getValue)
+              hasNextInput = inputIterator.next()
+              findNextPartition = inputIterator.getKey != groupingKey
+            }

Review Comment:
   yea, it is used to avoid unnecessary grouping key comparation. Before, it 
gets grouping key by comparing input rows and aggregation buffer, but it do 
compare again when updating or merging aggregation buffer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to