@Override
    public void doProcessBatch(VectorizedRowBatch batch, boolean isFirstGroupingSet,
        boolean[] currentGroupingSetsOverrideIsNulls) throws HiveException {

      if (!groupingSetsPresent || isFirstGroupingSet) {

        // Evaluate the key expressions once.
        for(int i = 0; i < keyExpressions.length; ++i) {
          keyExpressions[i].evaluate(batch);
        }
      }

      // First we traverse the batch to evaluate and prepare the KeyWrappers
      // After this the KeyWrappers are properly set and hash code is computed
      if (!groupingSetsPresent) {
        keyWrappersBatch.evaluateBatch(batch);
      } else {
        keyWrappersBatch.evaluateBatchGroupingSets(batch, currentGroupingSetsOverrideIsNulls);
      }

      VectorHashKeyWrapperBase[] batchKeys = keyWrappersBatch.getVectorHashKeyWrappers();

      final VectorHashKeyWrapperBase prevKey = streamingKey;
      if (streamingKey == null) {
        // This is the first batch we process after switching from hash mode
        aggregationBufferSet = streamAggregationBufferRowPool.getFromPool();
        streamingKey = batchKeys[0];
      }

      aggregationBatchInfo.startBatch();
      int flushMark = 0;

      for(int i = 0; i < batch.size; ++i) {
        if (!batchKeys[i].equals(streamingKey)) {
          // We've encountered a new key, must save current one
          // We can't forward yet, the aggregators have not been evaluated
          rowsToFlush[flushMark] = aggregationBufferSet;
          keysToFlush[flushMark] = streamingKey;
          aggregationBufferSet = streamAggregationBufferRowPool.getFromPool();
          streamingKey = batchKeys[i];
          ++flushMark;
        }
        aggregationBatchInfo.mapAggregationBufferSet(aggregationBufferSet, i);
      }

      // evaluate the aggregators
      processAggregators(batch);

      // Now flush/forward all keys/rows, except the last (current) one
      for (int i = 0; i < flushMark; ++i) {
        finishAggregators(rowsToFlush[i], false); //finish aggregations before flushing
        writeSingleRow(keysToFlush[i], rowsToFlush[i]);
        rowsToFlush[i].reset();
        keysToFlush[i] = null;
        streamAggregationBufferRowPool.putInPool(rowsToFlush[i]);
      }

      if (streamingKey != prevKey) {
        streamingKey = (VectorHashKeyWrapperBase) streamingKey.copyKey();
      }
    }
A pool of VectorAggregationBufferRow to avoid repeated allocations
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorGroupByOperator.java