@Test public void testNull() { Accumulator accumulator = factory.createAccumulator(); Block result = getFinalBlock(accumulator); assertTrue(result.getPositionCount() == 1); assertTrue(result.isNull(0)); }
@Test public void testNull() { Accumulator accumulator = factory.createAccumulator(); Block result = getFinalBlock(accumulator); assertTrue(result.getPositionCount() == 1); assertTrue(result.isNull(0)); }
@Test(expectedExceptions = PrestoException.class) public void testBadNumberOfBuckets() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(makeInput(0)); getFinalBlock(singleStep); }
@Test(expectedExceptions = PrestoException.class) public void testBadNumberOfBuckets() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(makeInput(0)); getFinalBlock(singleStep); }
@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<Double, Double> expected = Maps.transformValues(extractSingleValue(singleStepResult), value -> value * 2); assertEquals(extractSingleValue(actual), 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); }
private static Object aggregation(InternalAggregationFunction function, int[] args, Optional<Integer> maskChannel, Page... pages) { Accumulator aggregation = function.bind(Ints.asList(args), maskChannel).createAccumulator(); for (Page page : pages) { if (page.getPositionCount() > 0) { aggregation.addInput(page); } } Block block = getFinalBlock(aggregation); return BlockAssertions.getOnlyValue(aggregation.getFinalType(), block); }
@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 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); }
@Test public void testNull() throws Exception { Accumulator accumulator = factory.createAccumulator(); Block result = getFinalBlock(accumulator); assertTrue(result.getPositionCount() == 1); assertTrue(result.isNull(0)); }
@Test(expectedExceptions = PrestoException.class) public void testBadNumberOfBuckets() { Accumulator singleStep = factory.createAccumulator(); singleStep.addInput(makeInput(0)); getFinalBlock(singleStep); }
public static boolean approximateAggregationWithinErrorBound(InternalAggregationFunction function, int sampleWeightChannel, double confidence, Double expectedValue, Page... pages) { Accumulator accumulator = function.bind(ImmutableList.of(0), Optional.empty(), Optional.of(sampleWeightChannel), confidence).createAccumulator(); for (Page page : pages) { accumulator.addInput(page); } Block result = getFinalBlock(accumulator); if (expectedValue == null) { return BlockAssertions.toValues(function.getFinalType(), result).get(0) == null; } return withinErrorBound(BlockAssertions.toValues(function.getFinalType(), result).get(0).toString(), expectedValue); }
@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)); }
@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); }
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); }
private static Object aggregation(InternalAggregationFunction function, int[] args, Optional<Integer> maskChannel, double confidence, Page... pages) { Accumulator aggregation = function.bind(Ints.asList(args), maskChannel, Optional.empty(), confidence).createAccumulator(); for (Page page : pages) { if (page.getPositionCount() > 0) { aggregation.addInput(page); } } Block block = getFinalBlock(aggregation); return BlockAssertions.getOnlyValue(aggregation.getFinalType(), block); }
@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 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); }