Search in sources :

Example 1 with GroupedAggregator

use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.

the class InMemoryHashAggregationBuilder method getSizeInMemory.

public long getSizeInMemory() {
    long sizeInMemory = groupByHash.getEstimatedSize();
    for (GroupedAggregator groupedAggregator : groupedAggregators) {
        sizeInMemory += groupedAggregator.getEstimatedSize();
    }
    updateIsFull(sizeInMemory);
    return sizeInMemory;
}
Also used : GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator)

Example 2 with GroupedAggregator

use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.

the class TestSpatialPartitioningInternalAggregation method test.

@Test(dataProvider = "partitionCount")
public void test(int partitionCount) {
    TestingAggregationFunction 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);
    AggregatorFactory aggregatorFactory = function.createAggregatorFactory(SINGLE, Ints.asList(0, 1), OptionalInt.empty());
    Page page = new Page(geometryBlock, partitionCountBlock);
    Aggregator aggregator = aggregatorFactory.createAggregator();
    aggregator.processPage(page);
    String aggregation = (String) BlockAssertions.getOnlyValue(function.getFinalType(), getFinalBlock(function.getFinalType(), aggregator));
    assertEquals(aggregation, expectedValue);
    GroupedAggregator groupedAggregator = aggregatorFactory.createGroupedAggregator();
    groupedAggregator.processPage(createGroupByIdBlock(0, page.getPositionCount()), page);
    String groupValue = (String) getGroupValue(function.getFinalType(), groupedAggregator, 0);
    assertEquals(groupValue, expectedValue);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) Rectangle(io.trino.geospatial.Rectangle) AggregationTestUtils.createGroupByIdBlock(io.trino.operator.aggregation.AggregationTestUtils.createGroupByIdBlock) AggregationTestUtils.getFinalBlock(io.trino.operator.aggregation.AggregationTestUtils.getFinalBlock) Block(io.trino.spi.block.Block) Aggregator(io.trino.operator.aggregation.Aggregator) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) Page(io.trino.spi.Page) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory) TestingAggregationFunction(io.trino.operator.aggregation.TestingAggregationFunction) Test(org.testng.annotations.Test)

Example 3 with GroupedAggregator

use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.

the class InMemoryHashAggregationBuilder method buildResult.

private WorkProcessor<Page> buildResult(IntIterator groupIds) {
    PageBuilder pageBuilder = new PageBuilder(buildTypes());
    return WorkProcessor.create(() -> {
        if (!groupIds.hasNext()) {
            return ProcessState.finished();
        }
        pageBuilder.reset();
        List<Type> types = groupByHash.getTypes();
        while (!pageBuilder.isFull() && groupIds.hasNext()) {
            int groupId = groupIds.nextInt();
            groupByHash.appendValuesTo(groupId, pageBuilder, 0);
            pageBuilder.declarePosition();
            for (int i = 0; i < groupedAggregators.size(); i++) {
                GroupedAggregator groupedAggregator = groupedAggregators.get(i);
                BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
                groupedAggregator.evaluate(groupId, output);
            }
        }
        return ProcessState.ofResult(pageBuilder.build());
    });
}
Also used : Type(io.trino.spi.type.Type) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 4 with GroupedAggregator

use of io.trino.operator.aggregation.GroupedAggregator in project trino by trinodb.

the class SkipAggregationBuilder method serializeAccumulatorState.

private BlockBuilder[] serializeAccumulatorState(int positionCount) {
    BlockBuilder[] outputBuilders = new BlockBuilder[groupedAggregators.size()];
    for (int i = 0; i < outputBuilders.length; i++) {
        outputBuilders[i] = groupedAggregators.get(i).getType().createBlockBuilder(null, positionCount);
    }
    for (int position = 0; position < positionCount; position++) {
        for (int i = 0; i < groupedAggregators.size(); i++) {
            GroupedAggregator groupedAggregator = groupedAggregators.get(i);
            BlockBuilder output = outputBuilders[i];
            groupedAggregator.evaluate(position, output);
        }
    }
    return outputBuilders;
}
Also used : GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

GroupedAggregator (io.trino.operator.aggregation.GroupedAggregator)4 BlockBuilder (io.trino.spi.block.BlockBuilder)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 Rectangle (io.trino.geospatial.Rectangle)1 AggregationTestUtils.createGroupByIdBlock (io.trino.operator.aggregation.AggregationTestUtils.createGroupByIdBlock)1 AggregationTestUtils.getFinalBlock (io.trino.operator.aggregation.AggregationTestUtils.getFinalBlock)1 Aggregator (io.trino.operator.aggregation.Aggregator)1 AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)1 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)1 Page (io.trino.spi.Page)1 PageBuilder (io.trino.spi.PageBuilder)1 Block (io.trino.spi.block.Block)1 Type (io.trino.spi.type.Type)1 Test (org.testng.annotations.Test)1