Search in sources :

Example 1 with GroupedAccumulator

use of com.facebook.presto.operator.aggregation.GroupedAccumulator in project presto by prestodb.

the class TestSpatialPartitioningInternalAggregation method test.

@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());
    String expectedValue = getSpatialPartitioning(geometries, partitionCount);
    AccumulatorFactory accumulatorFactory = function.bind(Ints.asList(0, 1), Optional.empty());
    Page page = new Page(geometryBlock, partitionCountBlock);
    Accumulator accumulator = accumulatorFactory.createAccumulator(UpdateMemory.NOOP);
    accumulator.addInput(page);
    String aggregation = (String) BlockAssertions.getOnlyValue(accumulator.getFinalType(), getFinalBlock(accumulator));
    assertEquals(aggregation, expectedValue);
    GroupedAccumulator groupedAggregation = accumulatorFactory.createGroupedAccumulator(UpdateMemory.NOOP);
    groupedAggregation.addInput(createGroupByIdBlock(0, page.getPositionCount()), page);
    String groupValue = (String) getGroupValue(groupedAggregation, 0);
    assertEquals(groupValue, expectedValue);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GroupedAccumulator(com.facebook.presto.operator.aggregation.GroupedAccumulator) Accumulator(com.facebook.presto.operator.aggregation.Accumulator) AccumulatorFactory(com.facebook.presto.operator.aggregation.AccumulatorFactory) AggregationTestUtils.createGroupByIdBlock(com.facebook.presto.operator.aggregation.AggregationTestUtils.createGroupByIdBlock) AggregationTestUtils.getFinalBlock(com.facebook.presto.operator.aggregation.AggregationTestUtils.getFinalBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) GroupedAccumulator(com.facebook.presto.operator.aggregation.GroupedAccumulator) Test(org.testng.annotations.Test)

Example 2 with GroupedAccumulator

use of com.facebook.presto.operator.aggregation.GroupedAccumulator in project presto by prestodb.

the class AggregationTestInput method runPagesOnAccumulatorWithAssertion.

public void runPagesOnAccumulatorWithAssertion(long groupId, GroupedAccumulator groupedAccumulator, AggregationTestOutput expectedValue) {
    GroupedAccumulator accumulator = Suppliers.ofInstance(groupedAccumulator).get();
    for (Page page : getPages()) {
        accumulator.addInput(getGroupIdBlock(groupId, page), page);
    }
    expectedValue.validateAccumulator(accumulator, groupId);
}
Also used : Page(com.facebook.presto.common.Page) GroupedAccumulator(com.facebook.presto.operator.aggregation.GroupedAccumulator)

Aggregations

Page (com.facebook.presto.common.Page)2 GroupedAccumulator (com.facebook.presto.operator.aggregation.GroupedAccumulator)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 Block (com.facebook.presto.common.block.Block)1 Accumulator (com.facebook.presto.operator.aggregation.Accumulator)1 AccumulatorFactory (com.facebook.presto.operator.aggregation.AccumulatorFactory)1 AggregationTestUtils.createGroupByIdBlock (com.facebook.presto.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (com.facebook.presto.operator.aggregation.AggregationTestUtils.getFinalBlock)1 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)1 Test (org.testng.annotations.Test)1