public static Object groupedAggregation(InternalAggregationFunction function, int[] args, Page... pages) { GroupedAccumulator groupedAggregation = function.bind(Ints.asList(args), Optional.empty()).createGroupedAccumulator(); for (Page page : pages) { groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); } Object groupValue = getGroupValue(groupedAggregation, 0); for (Page page : pages) { groupedAggregation.addInput(createGroupByIdBlock(4000, page.getPositionCount()), page); } Object largeGroupValue = getGroupValue(groupedAggregation, 4000); assertEquals(largeGroupValue, groupValue, "Inconsistent results with large group id"); return groupValue; }
@Test(dataProvider = "partitionCount") public void test(int partitionCount) { InternalAggregationFunction function = getFunction(); List<OGCGeometry> geometries = makeGeometries(); Block geometryBlock = makeGeometryBlock(geometries); Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size()); Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0)); String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount); AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty()); Page page = new Page(geometryBlock, partitionCountBlock); Accumulator accumulator = accumulatorFactory.createAccumulator(); accumulator.addInput(page); String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator)); assertEquals(aggregation, expectedValue); GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(); groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); String groupValue = (String) getGroupValue(groupedAggregation, 0); assertEquals(groupValue, expectedValue); }
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 groupedApproximateAggregationWithinErrorBound(InternalAggregationFunction function, int sampleWeightChannel, double confidence, Double expectedValue, Page... pages) { GroupedAccumulator groupedAggregation = function.bind(ImmutableList.of(0), Optional.empty(), Optional.of(sampleWeightChannel), confidence).createGroupedAccumulator(); for (Page page : pages) { groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); } Object groupValue = getGroupValue(groupedAggregation, 0); if (expectedValue == null) { return groupValue == null; } return withinErrorBound(groupValue.toString(), expectedValue); }
public static Object groupedAggregation(InternalAggregationFunction function, double confidence, int[] args, Page... pages) { GroupedAccumulator groupedAggregation = function.bind(Ints.asList(args), Optional.empty(), Optional.empty(), confidence).createGroupedAccumulator(); for (Page page : pages) { groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); } Object groupValue = getGroupValue(groupedAggregation, 0); for (Page page : pages) { groupedAggregation.addInput(createGroupByIdBlock(4000, page.getPositionCount()), page); } Object largeGroupValue = getGroupValue(groupedAggregation, 4000); assertEquals(largeGroupValue, groupValue, "Inconsistent results with large group id"); return groupValue; }
@Test(dataProvider = "partitionCount") public void test(int partitionCount) { InternalAggregationFunction function = getFunction(); List<OGCGeometry> geometries = makeGeometries(); Block geometryBlock = makeGeometryBlock(geometries); Block partitionCountBlock = BlockAssertions.createRLEBlock(partitionCount, geometries.size()); Rectangle expectedExtent = new Rectangle(-10, -10, Math.nextUp(10.0), Math.nextUp(10.0)); String expectedValue = getSpatialPartitioning(expectedExtent, geometries, partitionCount); AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1, 2), Optional.empty()); Page page = new Page(geometryBlock, partitionCountBlock); Accumulator accumulator = accumulatorFactory.createAccumulator(); accumulator.addInput(page); String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator)); assertEquals(aggregation, expectedValue); GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(); groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page); String groupValue = (String) getGroupValue(groupedAggregation, 0); assertEquals(groupValue, expectedValue); }
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); }