Search in sources :

Example 1 with AggregatorFactory

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

the class InMemoryHashAggregationBuilder method toTypes.

public static List<Type> toTypes(List<? extends Type> groupByType, List<AggregatorFactory> factories, Optional<Integer> hashChannel) {
    ImmutableList.Builder<Type> types = ImmutableList.builder();
    types.addAll(groupByType);
    if (hashChannel.isPresent()) {
        types.add(BIGINT);
    }
    for (AggregatorFactory factory : factories) {
        types.add(factory.createAggregator().getType());
    }
    return types.build();
}
Also used : Type(io.trino.spi.type.Type) ImmutableList(com.google.common.collect.ImmutableList) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory)

Example 2 with AggregatorFactory

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

the class HashAggregationOperator method getGlobalAggregationOutput.

private Page getGlobalAggregationOutput() {
    // global aggregation output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
    for (int groupId : globalAggregationGroupIds) {
        output.declarePosition();
        int channel = 0;
        while (channel < groupByTypes.size()) {
            if (channel == groupIdChannel.orElseThrow()) {
                output.getBlockBuilder(channel).writeLong(groupId);
            } else {
                output.getBlockBuilder(channel).appendNull();
            }
            channel++;
        }
        if (hashChannel.isPresent()) {
            long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.orElseThrow(), groupId);
            output.getBlockBuilder(channel).writeLong(hashValue);
            channel++;
        }
        for (AggregatorFactory aggregatorFactory : aggregatorFactories) {
            aggregatorFactory.createAggregator().evaluate(output.getBlockBuilder(channel));
            channel++;
        }
    }
    if (output.isEmpty()) {
        return null;
    }
    return output.build();
}
Also used : PageBuilder(io.trino.spi.PageBuilder) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory)

Example 3 with AggregatorFactory

use of io.trino.operator.aggregation.AggregatorFactory 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 4 with AggregatorFactory

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

the class TestAggregationOperator method testDistinctMaskWithNulls.

@Test
public void testDistinctMaskWithNulls() {
    AggregatorFactory distinctFactory = LONG_SUM.createDistinctAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(distinctFactory));
    ByteArrayBlock trueMaskAllNull = new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, true, true }), /* all positions are null */
    new byte[] { 1, 1, 1, 1 });
    /* non-zero value is true, all masks are true */
    Block trueNullRleMask = new RunLengthEncodedBlock(trueMaskAllNull.getSingleValueBlock(0), 4);
    List<Page> nullTrueMaskInput = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), trueMaskAllNull), new Page(4, createLongsBlock(10, 11, 10, 11), createBooleansBlock(true, true, true, true)), new Page(4, createLongsBlock(5, 6, 7, 8), trueNullRleMask));
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(21L).build();
    assertOperatorEquals(operatorFactory, driverContext, nullTrueMaskInput, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) BlockAssertions.createBooleansBlock(io.trino.block.BlockAssertions.createBooleansBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Page(io.trino.spi.Page) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)4 Page (io.trino.spi.Page)2 Block (io.trino.spi.block.Block)2 Test (org.testng.annotations.Test)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 ImmutableList (com.google.common.collect.ImmutableList)1 BlockAssertions.createBooleansBlock (io.trino.block.BlockAssertions.createBooleansBlock)1 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)1 Rectangle (io.trino.geospatial.Rectangle)1 AggregationOperatorFactory (io.trino.operator.AggregationOperator.AggregationOperatorFactory)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 GroupedAggregator (io.trino.operator.aggregation.GroupedAggregator)1 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)1 PageBuilder (io.trino.spi.PageBuilder)1 ByteArrayBlock (io.trino.spi.block.ByteArrayBlock)1 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)1 Type (io.trino.spi.type.Type)1 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)1