@Test public void testMerge() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block singleStepResult = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block intermediate = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(intermediate); finalStep.addIntermediate(intermediate); Block actual = getFinalBlock(finalStep); Map<Double, Double> expected = Maps.transformValues(extractSingleValue(singleStepResult), value -> value * 2); assertEquals(extractSingleValue(actual), expected); }
@Test public void test() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block expected = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block partialBlock = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(partialBlock); Block actual = getFinalBlock(finalStep); assertEquals(extractSingleValue(actual), extractSingleValue(expected)); }
@Test public void test() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block expected = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block partialBlock = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(partialBlock); Block actual = getFinalBlock(finalStep); assertEquals(extractSingleValue(actual), extractSingleValue(expected)); }
@Test public void testMerge() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block singleStepResult = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block intermediate = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(intermediate); finalStep.addIntermediate(intermediate); Block actual = getFinalBlock(finalStep); Map<Float, Float> expected = Maps.transformValues(extractSingleValue(singleStepResult), value -> value * 2); assertEquals(extractSingleValue(actual), expected); }
public static Object partialAggregation(InternalAggregationFunction function, int[] args, Page... pages) { AccumulatorFactory factory = function.bind(Ints.asList(args), Optional.empty()); Accumulator finalAggregation = factory.createIntermediateAccumulator(); // Test handling of empty intermediate blocks Accumulator emptyAggregation = factory.createAccumulator(); Block emptyBlock = getIntermediateBlock(emptyAggregation); finalAggregation.addIntermediate(emptyBlock); for (Page page : pages) { Accumulator partialAggregation = factory.createAccumulator(); if (page.getPositionCount() > 0) { partialAggregation.addInput(page); } Block partialBlock = getIntermediateBlock(partialAggregation); finalAggregation.addIntermediate(partialBlock); } finalAggregation.addIntermediate(emptyBlock); Block finalBlock = getFinalBlock(finalAggregation); return BlockAssertions.getOnlyValue(finalAggregation.getFinalType(), finalBlock); }
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 static boolean partialApproximateAggregationWithinErrorBound(InternalAggregationFunction function, int sampleWeightChannel, double confidence, Double expectedValue, Page... pages) { AccumulatorFactory factory = function.bind(ImmutableList.of(0), Optional.empty(), Optional.of(sampleWeightChannel), confidence); Accumulator partialAccumulator = factory.createAccumulator(); for (Page page : pages) { if (page.getPositionCount() > 0) { partialAccumulator.addInput(page); } } Block partialBlock = getIntermediateBlock(partialAccumulator); Accumulator finalAggregation = factory.createIntermediateAccumulator(); finalAggregation.addIntermediate(partialBlock); Block finalBlock = getFinalBlock(finalAggregation); if (expectedValue == null) { return BlockAssertions.toValues(function.getFinalType(), finalBlock).get(0) == null; } return withinErrorBound(BlockAssertions.toValues(function.getFinalType(), finalBlock).get(0).toString(), expectedValue); }
@Test public void testMerge() throws Exception { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block singleStepResult = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block intermediate = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(intermediate); finalStep.addIntermediate(intermediate); Block actual = getFinalBlock(finalStep); Map<Double, Double> expected = Maps.transformValues(extractSingleValue(singleStepResult), value -> value * 2); assertEquals(extractSingleValue(actual), expected); }
@Test public void test() throws Exception { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(input); Block expected = getFinalBlock(singleStep); Accumulator partialStep = factory.createAccumulator(); partialStep.addInput(input); Block partialBlock = getIntermediateBlock(partialStep); Accumulator finalStep = factory.createAccumulator(); finalStep.addIntermediate(partialBlock); Block actual = getFinalBlock(finalStep); assertEquals(extractSingleValue(actual), extractSingleValue(expected)); }
public static Object partialAggregation(InternalAggregationFunction function, double confidence, int[] args, Page... pages) { AccumulatorFactory factory = function.bind(Ints.asList(args), Optional.empty(), Optional.empty(), confidence); Accumulator finalAggregation = factory.createIntermediateAccumulator(); // Test handling of empty intermediate blocks Accumulator emptyAggregation = factory.createAccumulator(); Block emptyBlock = getIntermediateBlock(emptyAggregation); finalAggregation.addIntermediate(emptyBlock); for (Page page : pages) { Accumulator partialAggregation = factory.createAccumulator(); if (page.getPositionCount() > 0) { partialAggregation.addInput(page); } Block partialBlock = getIntermediateBlock(partialAggregation); finalAggregation.addIntermediate(partialBlock); } finalAggregation.addIntermediate(emptyBlock); Block finalBlock = getFinalBlock(finalAggregation); return BlockAssertions.getOnlyValue(finalAggregation.getFinalType(), finalBlock); }
public static Object groupedPartialAggregation(InternalAggregationFunction function, double confidence, int[] args, Page... pages) { AccumulatorFactory factory = function.bind(Ints.asList(args), Optional.empty(), Optional.empty(), confidence); 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); }