@Override public long getEstimatedSize() { long estimatedSize = INSTANCE_SIZE; if (typedHeap != null) { estimatedSize += typedHeap.getEstimatedSize(); } return estimatedSize; }
@Override public void setTypedHeap(TypedHeap value) { TypedHeap previous = getTypedHeap(); if (previous != null) { size -= previous.getEstimatedSize(); } heaps.set(getGroupId(), value); size += value.getEstimatedSize(); }
public static void combine(MinMaxNState state, MinMaxNState otherState) { TypedHeap otherHeap = otherState.getTypedHeap(); if (otherHeap == null) { return; } TypedHeap heap = state.getTypedHeap(); if (heap == null) { state.setTypedHeap(otherHeap); return; } long startSize = heap.getEstimatedSize(); heap.addAll(otherHeap); state.addMemoryUsage(heap.getEstimatedSize() - startSize); }
public static void input(BlockComparator comparator, Type type, MinMaxNState state, Block block, long n, int blockIndex) { TypedHeap heap = state.getTypedHeap(); if (heap == null) { if (n <= 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "second argument of max_n/min_n must be positive"); } checkCondition(n <= MAX_NUMBER_OF_VALUES, INVALID_FUNCTION_ARGUMENT, "second argument of max_n/min_n must be less than or equal to %s; found %s", MAX_NUMBER_OF_VALUES, n); heap = new TypedHeap(comparator, type, toIntExact(n)); state.setTypedHeap(heap); } long startSize = heap.getEstimatedSize(); heap.add(block, blockIndex); state.addMemoryUsage(heap.getEstimatedSize() - startSize); }
public static void output(ArrayType outputType, MinMaxNState state, BlockBuilder out) { TypedHeap heap = state.getTypedHeap(); if (heap == null || heap.isEmpty()) { out.appendNull(); return; } Type elementType = outputType.getElementType(); BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(null, heap.getCapacity()); long startSize = heap.getEstimatedSize(); heap.popAll(reversedBlockBuilder); state.addMemoryUsage(heap.getEstimatedSize() - startSize); BlockBuilder arrayBlockBuilder = out.beginBlockEntry(); for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) { elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder); } out.closeEntry(); } }
@Override public long getEstimatedSize() { if (typedHeap == null) { return 0; } return typedHeap.getEstimatedSize(); }
@Override public void setTypedHeap(TypedHeap value) { TypedHeap previous = getTypedHeap(); if (previous != null) { size -= previous.getEstimatedSize(); } heaps.set(getGroupId(), value); size += value.getEstimatedSize(); }
public static void input(BlockComparator comparator, Type type, MinMaxNState state, Block block, long n, int blockIndex) { TypedHeap heap = state.getTypedHeap(); if (heap == null) { if (n <= 0) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "second argument of max_n/min_n must be positive"); } heap = new TypedHeap(comparator, type, Ints.checkedCast(n)); state.setTypedHeap(heap); } long startSize = heap.getEstimatedSize(); heap.add(block, blockIndex); state.addMemoryUsage(heap.getEstimatedSize() - startSize); }
public static void combine(MinMaxNState state, MinMaxNState otherState) { TypedHeap otherHeap = otherState.getTypedHeap(); if (otherHeap == null) { return; } TypedHeap heap = state.getTypedHeap(); if (heap == null) { state.setTypedHeap(otherHeap); return; } long startSize = heap.getEstimatedSize(); heap.addAll(otherHeap); state.addMemoryUsage(heap.getEstimatedSize() - startSize); }
public static void output(ArrayType outputType, MinMaxNState state, BlockBuilder out) { TypedHeap heap = state.getTypedHeap(); if (heap == null || heap.isEmpty()) { out.appendNull(); return; } Type elementType = outputType.getElementType(); BlockBuilder reversedBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), heap.getCapacity()); long startSize = heap.getEstimatedSize(); heap.popAll(reversedBlockBuilder); state.addMemoryUsage(heap.getEstimatedSize() - startSize); BlockBuilder arrayBlockBuilder = out.beginBlockEntry(); for (int i = reversedBlockBuilder.getPositionCount() - 1; i >= 0; i--) { elementType.appendTo(reversedBlockBuilder, i, arrayBlockBuilder); } out.closeEntry(); } }