use of com.facebook.presto.execution.TaskMetadataContext in project presto by prestodb.
the class TestTableWriterOperator method createTableWriterOperator.
private Operator createTableWriterOperator(PageSinkManager pageSinkManager, OperatorFactory statisticsAggregation, List<Type> outputTypes, Session session) {
TaskContext taskContext = createTaskContext(executor, scheduledExecutor, session);
DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
TaskMetadataContext taskMetadataContext = taskContext.getTaskMetadataContext();
return createTableWriterOperator(pageSinkManager, statisticsAggregation, outputTypes, session, taskMetadataContext, driverContext);
}
use of com.facebook.presto.execution.TaskMetadataContext 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);
}
Aggregations