use of com.facebook.presto.operator.aggregation.TypedKeyValueHeap in project presto by prestodb.
the class AbstractMinMaxByNAggregationFunction method input.
public static void input(BlockComparator comparator, Type valueType, Type keyType, MinMaxByNState state, Block value, Block key, int blockIndex, long n) {
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null) {
if (n <= 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "third argument of max_by/min_by must be a positive integer");
}
checkCondition(n <= MAX_NUMBER_OF_VALUES, INVALID_FUNCTION_ARGUMENT, "third argument of max_by/min_by must be less than or equal to %s; found %s", MAX_NUMBER_OF_VALUES, n);
heap = new TypedKeyValueHeap(comparator, keyType, valueType, toIntExact(n));
state.setTypedKeyValueHeap(heap);
}
long startSize = heap.getEstimatedSize();
if (!key.isNull(blockIndex)) {
heap.add(key, value, blockIndex);
}
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
}
use of com.facebook.presto.operator.aggregation.TypedKeyValueHeap in project presto by prestodb.
the class AbstractMinMaxByNAggregationFunction method output.
public static void output(ArrayType outputType, MinMaxByNState state, BlockBuilder out) {
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null || heap.isEmpty()) {
out.appendNull();
return;
}
Type elementType = outputType.getElementType();
BlockBuilder arrayBlockBuilder = out.beginBlockEntry();
BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(null, heap.getCapacity());
long startSize = heap.getEstimatedSize();
heap.popAll(reversedBlockBuilder);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) {
elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder);
}
out.closeEntry();
}
use of com.facebook.presto.operator.aggregation.TypedKeyValueHeap in project presto by prestodb.
the class AbstractMinMaxByNAggregationFunction method combine.
public static void combine(MinMaxByNState state, MinMaxByNState otherState) {
TypedKeyValueHeap otherHeap = otherState.getTypedKeyValueHeap();
if (otherHeap == null) {
return;
}
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null) {
state.setTypedKeyValueHeap(otherHeap);
return;
}
long startSize = heap.getEstimatedSize();
heap.addAll(otherHeap);
state.addMemoryUsage(heap.getEstimatedSize() - startSize);
}
use of com.facebook.presto.operator.aggregation.TypedKeyValueHeap in project presto by prestodb.
the class MinMaxByNStateSerializer method serialize.
@Override
public void serialize(MinMaxByNState state, BlockBuilder out) {
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null) {
out.appendNull();
return;
}
heap.serialize(out);
}
use of com.facebook.presto.operator.aggregation.TypedKeyValueHeap in project presto by prestodb.
the class MinMaxByNStateSerializer method serialize.
@Override
public void serialize(MinMaxByNState state, BlockBuilder out) {
TypedKeyValueHeap heap = state.getTypedKeyValueHeap();
if (heap == null) {
out.appendNull();
return;
}
heap.serialize(out);
}
Aggregations