public void processPage(GroupByIdBlock groupIds, Page page) { if (step.isInputRaw()) { aggregation.addInput(groupIds, page); } else { aggregation.addIntermediate(groupIds, page.getBlock(intermediateChannel)); } }
public void evaluate(int groupId, BlockBuilder output) { if (step.isOutputPartial()) { aggregation.evaluateIntermediate(groupId, output); } else { aggregation.evaluateFinal(groupId, output); } }
public Type getType() { if (step.isOutputPartial()) { return aggregation.getIntermediateType(); } else { return aggregation.getFinalType(); } }
public static Object getGroupValue(GroupedAccumulator groupedAggregation, int groupId) { BlockBuilder out = groupedAggregation.getFinalType().createBlockBuilder(null, 1); groupedAggregation.evaluateFinal(groupId, out); return BlockAssertions.getOnlyValue(groupedAggregation.getFinalType(), out.build()); }
@Benchmark public GroupedAccumulator testSharedGroupWithLargeBlocksRunner(Data data) { GroupedAccumulator groupedAccumulator = data.groupedAccumulator; for (int i = 0; i < data.numGroups; i++) { GroupByIdBlock groupByIdBlock = data.groupByIdBlocks[i]; Page page = data.pages[i]; groupedAccumulator.addInput(groupByIdBlock, page); } return groupedAccumulator; }
public static Block getIntermediateBlock(GroupedAccumulator accumulator) { BlockBuilder blockBuilder = accumulator.getIntermediateType().createBlockBuilder(null, 1000); accumulator.evaluateIntermediate(0, blockBuilder); return blockBuilder.build(); }
@Override public Type getFinalType() { return accumulator.getFinalType(); }
@Override public void evaluateFinal(int groupId, BlockBuilder output) { accumulator.evaluateFinal(groupId, output); }
public Type getIntermediateType() { return aggregation.getIntermediateType(); } }
public long getEstimatedSize() { return aggregation.getEstimatedSize(); }
private static Object getGroupValue(GroupedAccumulator groupedAggregation, int groupId) { BlockBuilder out = groupedAggregation.getFinalType().createBlockBuilder(null, 1); groupedAggregation.evaluateFinal(groupId, out); return BlockAssertions.getOnlyValue(groupedAggregation.getFinalType(), out.build()); } }
@Override public void prepareFinal() { pagesIndex.sort(orderByChannels, orderings); Iterator<Page> pagesIterator = pagesIndex.getSortedPages(); pagesIterator.forEachRemaining(page -> { // The last channel of the page is the group id GroupByIdBlock groupIds = new GroupByIdBlock(groupCount, page.getBlock(page.getChannelCount() - 1)); // We pass group id together with the other input channels to accumulator. Accumulator knows which input channels // to use. Since we did not change the order of original input channels, passing the group id is safe. accumulator.addInput(groupIds, page); }); } }
public static Block getIntermediateBlock(GroupedAccumulator accumulator) { BlockBuilder blockBuilder = accumulator.getIntermediateType().createBlockBuilder(new BlockBuilderStatus(), 1000); accumulator.evaluateIntermediate(0, blockBuilder); return blockBuilder.build(); }
@Override public Type getFinalType() { return accumulator.getFinalType(); }
@Override public void evaluateFinal(int groupId, BlockBuilder output) { accumulator.evaluateFinal(groupId, output); }
@Override public long getEstimatedSize() { return hash.getEstimatedSize() + accumulator.getEstimatedSize(); }
public static Block getFinalBlock(GroupedAccumulator accumulator) { BlockBuilder blockBuilder = accumulator.getFinalType().createBlockBuilder(null, 1000); accumulator.evaluateFinal(0, blockBuilder); return blockBuilder.build(); }
public static Object groupedPartialAggregation(InternalAggregationFunction function, int[] args, Page... pages) { AccumulatorFactory factory = function.bind(Ints.asList(args), Optional.empty()); GroupedAccumulator finalAggregation = factory.createGroupedIntermediateAccumulator(); // Add an empty block to test the handling of empty intermediates GroupedAccumulator emptyAggregation = factory.createGroupedAccumulator(); Block emptyBlock = getIntermediateBlock(emptyAggregation); finalAggregation.addIntermediate(createGroupByIdBlock(0, emptyBlock.getPositionCount()), emptyBlock); for (Page page : pages) { GroupedAccumulator partialAggregation = factory.createGroupedAccumulator(); partialAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); Block partialBlock = getIntermediateBlock(partialAggregation); finalAggregation.addIntermediate(createGroupByIdBlock(0, partialBlock.getPositionCount()), partialBlock); } finalAggregation.addIntermediate(createGroupByIdBlock(0, emptyBlock.getPositionCount()), emptyBlock); return getGroupValue(finalAggregation, 0); }
public GroupedAccumulator runPagesOnAccumulator(long groupId, Supplier<GroupedAccumulator> accumulatorSupplier) { GroupedAccumulator accumulator = accumulatorSupplier.get(); for (Page page : getPages()) { accumulator.addInput(getGroupIdBlock(groupId, page), page); } return accumulator; }
public void evaluate(int groupId, BlockBuilder output) { if (step.isOutputPartial()) { aggregation.evaluateIntermediate(groupId, output); } else { aggregation.evaluateFinal(groupId, output); } } }