/** * Return the aggregation buffer for the current group. For efficiency, all calls to this method * return the same object. If additional memory could not be allocated, then this method will * signal an error by returning null. */ public UnsafeRow getAggregationBuffer(InternalRow groupingKey) { final UnsafeRow unsafeGroupingKeyRow = this.groupingKeyProjection.apply(groupingKey); return getAggregationBufferFromUnsafeRow(unsafeGroupingKeyRow); }
/** * Return the aggregation buffer for the current group. For efficiency, all calls to this method * return the same object. If additional memory could not be allocated, then this method will * signal an error by returning null. */ public UnsafeRow getAggregationBuffer(InternalRow groupingKey) { final UnsafeRow unsafeGroupingKeyRow = this.groupingKeyProjection.apply(groupingKey); return getAggregationBufferFromUnsafeRow(unsafeGroupingKeyRow); }
/** * Return the aggregation buffer for the current group. For efficiency, all calls to this method * return the same object. If additional memory could not be allocated, then this method will * signal an error by returning null. */ public UnsafeRow getAggregationBuffer(InternalRow groupingKey) { final UnsafeRow unsafeGroupingKeyRow = this.groupingKeyProjection.apply(groupingKey); return getAggregationBufferFromUnsafeRow(unsafeGroupingKeyRow); }
/** * 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."); } } }
public UnsafeRow getAggregationBufferFromUnsafeRow(UnsafeRow key) { return getAggregationBufferFromUnsafeRow(key, key.hashCode()); }
@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(); } }
public UnsafeRow getAggregationBufferFromUnsafeRow(UnsafeRow key) { return getAggregationBufferFromUnsafeRow(key, key.hashCode()); }
public UnsafeRow getAggregationBufferFromUnsafeRow(UnsafeRow key) { return getAggregationBufferFromUnsafeRow(key, key.hashCode()); }
/** * Return the aggregation buffer for the current group. For efficiency, all calls to this method * return the same object. If additional memory could not be allocated, then this method will * signal an error by returning null. */ public UnsafeRow getAggregationBuffer(InternalRow groupingKey) { final UnsafeRow unsafeGroupingKeyRow = this.groupingKeyProjection.apply(groupingKey); return getAggregationBufferFromUnsafeRow(unsafeGroupingKeyRow); }
/** * Return the aggregation buffer for the current group. For efficiency, all calls to this method * return the same object. If additional memory could not be allocated, then this method will * signal an error by returning null. */ public UnsafeRow getAggregationBuffer(InternalRow groupingKey) { final UnsafeRow unsafeGroupingKeyRow = this.groupingKeyProjection.apply(groupingKey); return getAggregationBufferFromUnsafeRow(unsafeGroupingKeyRow); }
public UnsafeRow getAggregationBufferFromUnsafeRow(UnsafeRow key) { return getAggregationBufferFromUnsafeRow(key, key.hashCode()); }
private void processInputs() { if (groupingExpressions.isEmpty()) { // If there is no grouping expressions, we can just reuse the same buffer over and over again. // Note that it would be better to eliminate the hash map entirely in the future. UnsafeRow groupingKey = groupingProjection.apply(null); UnsafeRow buffer = hashMap.getAggregationBufferFromUnsafeRow(groupingKey); while (inputIter.hasNext()) { InternalRow newInput = inputIter.next(); processRow.apply(buffer, newInput); } } else { while (inputIter.hasNext()) { InternalRow newInput = inputIter.next(); UnsafeRow groupingKey = groupingProjection.apply(newInput); if (groupingKey.hasString()) { throw new RuntimeException("Grouping keys with string is not yet supported"); } UnsafeRow buffer = hashMap.getAggregationBufferFromUnsafeRow(groupingKey); if (buffer == null) { throw new RuntimeException("No enough memory for aggregation"); } processRow.apply(buffer, newInput); } } }