Search in sources :

Example 1 with TableWriterInfo

use of io.trino.operator.TableWriterOperator.TableWriterInfo in project trino by trinodb.

the class TestTableWriterOperator method testTableWriterInfo.

@Test
public void testTableWriterInfo() {
    PageSinkManager pageSinkManager = new PageSinkManager();
    pageSinkManager.addConnectorPageSinkProvider(CONNECTOR_ID, new ConstantPageSinkProvider(new TableWriteInfoTestPageSink()));
    TableWriterOperator tableWriterOperator = (TableWriterOperator) createTableWriterOperator(pageSinkManager, new DevNullOperatorFactory(1, new PlanNodeId("test")), ImmutableList.of(BIGINT, VARBINARY));
    RowPagesBuilder rowPagesBuilder = rowPagesBuilder(BIGINT);
    for (int i = 0; i < 100; i++) {
        rowPagesBuilder.addSequencePage(100, 0);
    }
    List<Page> pages = rowPagesBuilder.build();
    long peakMemoryUsage = 0;
    long validationCpuNanos = 0;
    for (int i = 0; i < pages.size(); i++) {
        Page page = pages.get(i);
        peakMemoryUsage += page.getRetainedSizeInBytes();
        validationCpuNanos += page.getPositionCount();
        tableWriterOperator.addInput(page);
        TableWriterInfo info = tableWriterOperator.getInfo();
        assertEquals(info.getPageSinkPeakMemoryUsage(), peakMemoryUsage);
        assertEquals((long) (info.getValidationCpuTime().getValue(NANOSECONDS)), validationCpuNanos);
    }
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TableWriterInfo(io.trino.operator.TableWriterOperator.TableWriterInfo) RowPagesBuilder(io.trino.RowPagesBuilder) DevNullOperatorFactory(io.trino.operator.DevNullOperator.DevNullOperatorFactory) Page(io.trino.spi.Page) PageSinkManager(io.trino.split.PageSinkManager) Test(org.testng.annotations.Test)

Example 2 with TableWriterInfo

use of io.trino.operator.TableWriterOperator.TableWriterInfo 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)

Aggregations

TableWriterInfo (io.trino.operator.TableWriterOperator.TableWriterInfo)2 PageSinkManager (io.trino.split.PageSinkManager)2 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)2 Test (org.testng.annotations.Test)2 RowPagesBuilder (io.trino.RowPagesBuilder)1 Session (io.trino.Session)1 AggregationOperatorFactory (io.trino.operator.AggregationOperator.AggregationOperatorFactory)1 DevNullOperatorFactory (io.trino.operator.DevNullOperator.DevNullOperatorFactory)1 Page (io.trino.spi.Page)1 ConnectorSession (io.trino.spi.connector.ConnectorSession)1 Type (io.trino.spi.type.Type)1