Search in sources :

Example 1 with AggregationOperatorFactory

use of io.prestosql.operator.AggregationOperator.AggregationOperatorFactory in project hetu-core by openlookeng.

the class TestTableWriterOperator method testStatisticsAggregationSnapshot.

@Test
public void testStatisticsAggregationSnapshot() 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"), AggregationNode.Step.SINGLE, ImmutableList.of(LONG_MAX.bind(ImmutableList.of(0), Optional.empty())), true), outputTypes, session, driverContext);
    operator.addInput(rowPagesBuilder(BIGINT).row(42).build().get(0));
    Object snapshot = operator.capture(operator.getOperatorContext().getDriverContext().getSerde());
    assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createExpectedMapping());
    operator.addInput(rowPagesBuilder(BIGINT).row(43).build().get(0));
    operator.restore(snapshot, operator.getOperatorContext().getDriverContext().getSerde());
    snapshot = operator.capture(operator.getOperatorContext().getDriverContext().getSerde());
    assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createExpectedMapping());
    operator.addInput(rowPagesBuilder(BIGINT).row(43).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertTrue(operator.needsInput());
    assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
    assertEquals(driverContext.getMemoryUsage(), 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.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) TableWriterInfo(io.prestosql.operator.TableWriterOperator.TableWriterInfo) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) PageSinkManager(io.prestosql.split.PageSinkManager) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 2 with AggregationOperatorFactory

use of io.prestosql.operator.AggregationOperator.AggregationOperatorFactory in project hetu-core by openlookeng.

the class TestAggregationOperator method testMemoryTracking.

private void testMemoryTracking(boolean useSystemMemory) throws Exception {
    Page input = getOnlyElement(rowPagesBuilder(BIGINT).addSequencePage(100, 0).build());
    OperatorFactory operatorFactory = new AggregationOperatorFactory(0, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(LONG_SUM.bind(ImmutableList.of(0), Optional.empty())), useSystemMemory);
    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);
        if (useSystemMemory) {
            assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
            assertEquals(driverContext.getMemoryUsage(), 0);
        } else {
            assertEquals(driverContext.getSystemMemoryUsage(), 0);
            assertThat(driverContext.getMemoryUsage()).isGreaterThan(0);
        }
        toPages(operator, emptyIterator());
    }
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    assertEquals(driverContext.getMemoryUsage(), 0);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) Page(io.prestosql.spi.Page)

Example 3 with AggregationOperatorFactory

use of io.prestosql.operator.AggregationOperator.AggregationOperatorFactory in project hetu-core by openlookeng.

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.getMetadata(), 0).compileProjection(field(0, BIGINT), Optional.empty());
    FilterAndProjectOperator.FilterAndProjectOperatorFactory tpchQuery6Operator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(1, new PlanNodeId("test"), () -> new PageProcessor(Optional.of(new TpchQuery6Filter()), ImmutableList.of(projection.get())), ImmutableList.of(DOUBLE), new DataSize(0, BYTE), 0);
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(2, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false);
    return ImmutableList.of(tableScanOperator, tpchQuery6Operator, aggregationOperator);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PageProjection(io.prestosql.operator.project.PageProjection) PageFunctionCompiler(io.prestosql.sql.gen.PageFunctionCompiler) PageProcessor(io.prestosql.operator.project.PageProcessor) OperatorFactory(io.prestosql.operator.OperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) DataSize(io.airlift.units.DataSize) FilterAndProjectOperator(io.prestosql.operator.FilterAndProjectOperator)

Example 4 with AggregationOperatorFactory

use of io.prestosql.operator.AggregationOperator.AggregationOperatorFactory in project hetu-core by openlookeng.

the class DoubleSumAggregationBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
    InternalAggregationFunction doubleSum = createTestMetadataManager().getFunctionAndTypeManager().getAggregateFunctionImplementation(new Signature(QualifiedObjectName.valueOfDefaultFunction("sum"), AGGREGATE, DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature()));
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false);
    return ImmutableList.of(tableScanOperator, aggregationOperator);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) OperatorFactory(io.prestosql.operator.OperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) Signature(io.prestosql.spi.function.Signature) InternalAggregationFunction(io.prestosql.operator.aggregation.InternalAggregationFunction)

Example 5 with AggregationOperatorFactory

use of io.prestosql.operator.AggregationOperator.AggregationOperatorFactory in project hetu-core by openlookeng.

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"), AggregationNode.Step.SINGLE, ImmutableList.of(LONG_MAX.bind(ImmutableList.of(0), Optional.empty())), true), 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.getSystemMemoryUsage()).isGreaterThan(0);
    assertEquals(driverContext.getMemoryUsage(), 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.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) TableWriterInfo(io.prestosql.operator.TableWriterOperator.TableWriterInfo) AggregationOperatorFactory(io.prestosql.operator.AggregationOperator.AggregationOperatorFactory) PageSinkManager(io.prestosql.split.PageSinkManager) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Aggregations

AggregationOperatorFactory (io.prestosql.operator.AggregationOperator.AggregationOperatorFactory)8 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)8 InternalAggregationFunction (io.prestosql.operator.aggregation.InternalAggregationFunction)4 Signature (io.prestosql.spi.function.Signature)4 Test (org.testng.annotations.Test)4 OperatorFactory (io.prestosql.operator.OperatorFactory)3 Page (io.prestosql.spi.Page)3 Session (io.prestosql.Session)2 TableWriterInfo (io.prestosql.operator.TableWriterOperator.TableWriterInfo)2 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)2 Type (io.prestosql.spi.type.Type)2 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)2 PageSinkManager (io.prestosql.split.PageSinkManager)2 MaterializedResult (io.prestosql.testing.MaterializedResult)2 DataSize (io.airlift.units.DataSize)1 FilterAndProjectOperator (io.prestosql.operator.FilterAndProjectOperator)1 PageProcessor (io.prestosql.operator.project.PageProcessor)1 PageProjection (io.prestosql.operator.project.PageProjection)1 PageFunctionCompiler (io.prestosql.sql.gen.PageFunctionCompiler)1