/** * Generate a output row when there is no input and there is no grouping expression. */ public UnsafeRow outputForEmptyGroupingKeyWithoutInput() { if (groupingExpressions.isEmpty()) { // We create a output row and copy it. So, we can free the map. UnsafeRow resultCopy = generateOutput.apply(UnsafeRow.createFromByteArray(0, 0), initialAggregationBuffer).copy(); hashMap.free(); return resultCopy; } else { throw new IllegalStateException("This method should not be called when groupingExpressions is not empty."); } } }
hashMap.free();
@Override public UnsafeRow next() { if (hasNext()) { UnsafeRow result = generateOutput.apply( aggregationBufferMapIterator.getKey(), aggregationBufferMapIterator.getValue()); try { // Pre-load next key-value pair form aggregationBufferMapIterator to make hasNext // idempotent. mapIteratorHasNext = aggregationBufferMapIterator.next(); } catch (IOException e) { throw new RuntimeException(e); } if (!mapIteratorHasNext) { // If there is no input from aggregationBufferMapIterator, we copy current result. UnsafeRow resultCopy = result.copy(); // Then, we free the map. hashMap.free(); return resultCopy; } else { return result; } } else { // no more result throw new NoSuchElementException(); } }