Search in sources :

Example 1 with AggregationOperatorFactory

use of io.trino.operator.AggregationOperator.AggregationOperatorFactory in project trino by trinodb.

the class TestAggregationOperator method testMaskWithDirtyNulls.

@Test
public void testMaskWithDirtyNulls() {
    List<Page> input = ImmutableList.of(new Page(4, createLongsBlock(1, 2, 3, 4), new ByteArrayBlock(4, Optional.of(new boolean[] { true, true, false, false }), new byte[] { 0, 27, /* dirty null */
    0, 75 /* non-zero value is true */
    })));
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(COUNT.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.of(1))));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT).row(1L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) Page(io.trino.spi.Page) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with AggregationOperatorFactory

use of io.trino.operator.AggregationOperator.AggregationOperatorFactory in project trino by trinodb.

the class HandTpchQuery6 method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    // select sum(extendedprice * discount) as revenue
    // from lineitem
    // where shipdate >= '1994-01-01'
    // and shipdate < '1995-01-01'
    // and discount >= 0.05
    // and discount <= 0.07
    // and quantity < 24;
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "lineitem", "extendedprice", "discount", "shipdate", "quantity");
    Supplier<PageProjection> projection = new PageFunctionCompiler(localQueryRunner.getFunctionManager(), 0).compileProjection(field(0, BIGINT), Optional.empty());
    OperatorFactory tpchQuery6Operator = FilterAndProjectOperator.createOperatorFactory(1, new PlanNodeId("test"), () -> new PageProcessor(Optional.of(new TpchQuery6Filter()), ImmutableList.of(projection.get())), ImmutableList.of(DOUBLE), DataSize.ofBytes(0), 0);
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(2, new PlanNodeId("test"), ImmutableList.of(doubleSum.bind(ImmutableList.of(0))));
    return ImmutableList.of(tableScanOperator, tpchQuery6Operator, aggregationOperator);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProjection(io.trino.operator.project.PageProjection) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) PageProcessor(io.trino.operator.project.PageProcessor) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory)

Example 3 with AggregationOperatorFactory

use of io.trino.operator.AggregationOperator.AggregationOperatorFactory in project trino by trinodb.

the class CountAggregationBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey");
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), ImmutableList.of(countFunction.bind(ImmutableList.of(0))));
    return ImmutableList.of(tableScanOperator, aggregationOperator);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory)

Example 4 with AggregationOperatorFactory

use of io.trino.operator.AggregationOperator.AggregationOperatorFactory in project trino by trinodb.

the class TestAggregationOperator method testMemoryTracking.

@Test
public void testMemoryTracking() throws Exception {
    Page input = getOnlyElement(rowPagesBuilder(BIGINT).addSequencePage(100, 0).build());
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(LONG_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty())));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    try (Operator operator = operatorFactory.createOperator(driverContext)) {
        assertTrue(operator.needsInput());
        operator.addInput(input);
        assertThat(driverContext.getMemoryUsage()).isGreaterThan(0);
        toPages(operator, emptyIterator());
    }
    assertEquals(driverContext.getMemoryUsage(), 0);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 5 with AggregationOperatorFactory

use of io.trino.operator.AggregationOperator.AggregationOperatorFactory 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

AggregationOperatorFactory (io.trino.operator.AggregationOperator.AggregationOperatorFactory)8 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)8 Test (org.testng.annotations.Test)5 Page (io.trino.spi.Page)4 OperatorFactory (io.trino.operator.OperatorFactory)3 MaterializedResult (io.trino.testing.MaterializedResult)3 ByteArrayBlock (io.trino.spi.block.ByteArrayBlock)2 Session (io.trino.Session)1 BlockAssertions.createBooleansBlock (io.trino.block.BlockAssertions.createBooleansBlock)1 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)1 TableWriterInfo (io.trino.operator.TableWriterOperator.TableWriterInfo)1 AggregatorFactory (io.trino.operator.aggregation.AggregatorFactory)1 TestingAggregationFunction (io.trino.operator.aggregation.TestingAggregationFunction)1 PageProcessor (io.trino.operator.project.PageProcessor)1 PageProjection (io.trino.operator.project.PageProjection)1 Block (io.trino.spi.block.Block)1 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 Type (io.trino.spi.type.Type)1 PageSinkManager (io.trino.split.PageSinkManager)1