Search in sources :

Example 1 with TableWriterInfo

use of com.facebook.presto.operator.TableWriterOperator.TableWriterInfo in project presto by prestodb.

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(com.facebook.presto.spi.plan.PlanNodeId) TableWriterInfo(com.facebook.presto.operator.TableWriterOperator.TableWriterInfo) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) DevNullOperatorFactory(com.facebook.presto.operator.DevNullOperator.DevNullOperatorFactory) Page(com.facebook.presto.common.Page) PageSinkManager(com.facebook.presto.split.PageSinkManager) Test(org.testng.annotations.Test)

Example 2 with TableWriterInfo

use of com.facebook.presto.operator.TableWriterOperator.TableWriterInfo in project presto by prestodb.

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, VARBINARY, BIGINT);
    Session session = testSessionBuilder().setSystemProperty("statistics_cpu_timer_enabled", "true").build();
    TaskContext taskContext = createTaskContext(executor, scheduledExecutor, session);
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    TaskMetadataContext taskMetadataContext = taskContext.getTaskMetadataContext();
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    InternalAggregationFunction longMaxFunction = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("max", fromTypes(BIGINT)));
    TableWriterOperator operator = (TableWriterOperator) createTableWriterOperator(pageSinkManager, new AggregationOperatorFactory(1, new PlanNodeId("test"), AggregationNode.Step.SINGLE, ImmutableList.of(longMaxFunction.bind(ImmutableList.of(0), Optional.empty())), true), outputTypes, session, taskMetadataContext, 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, getTableCommitContext(false), 43).build().get(0));
    BlockBuilder rowsBuilder = BIGINT.createBlockBuilder(null, 1);
    BlockBuilder fragmentsBuilder = VARBINARY.createBlockBuilder(null, 1);
    rowsBuilder.writeLong(1);
    fragmentsBuilder.appendNull();
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(2, null, getTableCommitContext(true), 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 : TestingTaskContext.createTaskContext(com.facebook.presto.testing.TestingTaskContext.createTaskContext) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) TaskMetadataContext(com.facebook.presto.execution.TaskMetadataContext) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) TableWriterInfo(com.facebook.presto.operator.TableWriterOperator.TableWriterInfo) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) PageSinkManager(com.facebook.presto.split.PageSinkManager) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Session(com.facebook.presto.Session) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

TableWriterInfo (com.facebook.presto.operator.TableWriterOperator.TableWriterInfo)2 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)2 PageSinkManager (com.facebook.presto.split.PageSinkManager)2 Test (org.testng.annotations.Test)2 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)1 Session (com.facebook.presto.Session)1 Page (com.facebook.presto.common.Page)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 Type (com.facebook.presto.common.type.Type)1 TaskMetadataContext (com.facebook.presto.execution.TaskMetadataContext)1 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)1 AggregationOperatorFactory (com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory)1 DevNullOperatorFactory (com.facebook.presto.operator.DevNullOperator.DevNullOperatorFactory)1 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 TestingTaskContext.createTaskContext (com.facebook.presto.testing.TestingTaskContext.createTaskContext)1