Search in sources :

Example 6 with AggregationOperatorFactory

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

the class TestAggregationOperator method testAggregation.

@Test
public void testAggregation() {
    TestingAggregationFunction countVarcharColumn = FUNCTION_RESOLUTION.getAggregateFunction(QualifiedName.of("count"), fromTypes(VARCHAR));
    TestingAggregationFunction maxVarcharColumn = FUNCTION_RESOLUTION.getAggregateFunction(QualifiedName.of("max"), fromTypes(VARCHAR));
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT, VARCHAR, BIGINT, REAL, DOUBLE, VARCHAR).addSequencePage(100, 0, 0, 300, 500, 400, 500, 500).build();
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(COUNT.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()), LONG_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(1), OptionalInt.empty()), LONG_AVERAGE.createAggregatorFactory(SINGLE, ImmutableList.of(1), OptionalInt.empty()), maxVarcharColumn.createAggregatorFactory(SINGLE, ImmutableList.of(2), OptionalInt.empty()), countVarcharColumn.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()), LONG_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(3), OptionalInt.empty()), REAL_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(4), OptionalInt.empty()), DOUBLE_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(5), OptionalInt.empty()), maxVarcharColumn.createAggregatorFactory(SINGLE, ImmutableList.of(6), OptionalInt.empty())));
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false).addDriverContext();
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, DOUBLE, VARCHAR, BIGINT, BIGINT, REAL, DOUBLE, VARCHAR).row(100L, 4950L, 49.5, "399", 100L, 54950L, 44950.0f, 54950.0, "599").build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
    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) MaterializedResult(io.trino.testing.MaterializedResult) TestingAggregationFunction(io.trino.operator.aggregation.TestingAggregationFunction) Test(org.testng.annotations.Test)

Example 7 with AggregationOperatorFactory

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

the class TestTableWriterOperator method testStatisticsAggregation.

@Test
public void testStatisticsAggregation() throws Exception {
    PageSinkManager pageSinkManager = new PageSinkManager();
    pageSinkManager.addConnectorPageSinkProvider(CONNECTOR_ID, new ConstantPageSinkProvider(new TableWriteInfoTestPageSink()));
    ImmutableList<Type> outputTypes = ImmutableList.of(BIGINT, VARBINARY, BIGINT);
    Session session = testSessionBuilder().setSystemProperty("statistics_cpu_timer_enabled", "true").build();
    DriverContext driverContext = createTaskContext(executor, scheduledExecutor, session).addPipelineContext(0, true, true, false).addDriverContext();
    TableWriterOperator operator = (TableWriterOperator) createTableWriterOperator(pageSinkManager, new AggregationOperatorFactory(1, new PlanNodeId("test"), ImmutableList.of(LONG_MAX.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()))), outputTypes, session, driverContext);
    operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0));
    operator.addInput(rowPagesBuilder(BIGINT).row(43).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertTrue(operator.needsInput());
    assertThat(driverContext.getMemoryUsage()).isGreaterThan(0);
    operator.finish();
    assertFalse(operator.isFinished());
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(null, null, 43).build().get(0));
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(2, null, null).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertFalse(operator.needsInput());
    assertTrue(operator.isFinished());
    operator.close();
    assertMemoryIsReleased(operator);
    TableWriterInfo info = operator.getInfo();
    assertThat(info.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertThat(info.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) TableWriterInfo(io.trino.operator.TableWriterOperator.TableWriterInfo) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) PageSinkManager(io.trino.split.PageSinkManager) Session(io.trino.Session) ConnectorSession(io.trino.spi.connector.ConnectorSession) Test(org.testng.annotations.Test)

Example 8 with AggregationOperatorFactory

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

the class DoubleSumAggregationBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), ImmutableList.of(doubleSum.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)

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