use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestTableFinishOperator method testStatisticsAggregation.
@Test
public void testStatisticsAggregation() throws Exception {
TestingTableFinisher tableFinisher = new TestingTableFinisher();
TestingPageSinkCommitter pageSinkCommitter = new TestingPageSinkCommitter();
ColumnStatisticMetadata statisticMetadata = new ColumnStatisticMetadata("column", MAX_VALUE);
StatisticAggregationsDescriptor<Integer> descriptor = new StatisticAggregationsDescriptor<>(ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(statisticMetadata, 0));
Session session = testSessionBuilder().setSystemProperty("statistics_cpu_timer_enabled", "true").build();
TableFinishOperatorFactory operatorFactory = new TableFinishOperatorFactory(0, new PlanNodeId("node"), tableFinisher, pageSinkCommitter, new AggregationOperator.AggregationOperatorFactory(1, new PlanNodeId("test"), AggregationNode.Step.SINGLE, ImmutableList.of(LONG_MAX.bind(ImmutableList.of(STATS_START_CHANNEL), Optional.empty())), true), descriptor, session, TABLE_COMMIT_CONTEXT_CODEC, false);
DriverContext driverContext = createTaskContext(scheduledExecutor, scheduledExecutor, session).addPipelineContext(0, true, true, false).addDriverContext();
TableFinishOperator operator = (TableFinishOperator) operatorFactory.createOperator(driverContext);
List<Type> inputTypes = ImmutableList.of(BIGINT, VARBINARY, VARBINARY, BIGINT);
byte[] tableCommitContextForStatsPage = getTableCommitContextBytes(Lifespan.taskWide(), 0, 0, NO_COMMIT, false);
operator.addInput(rowPagesBuilder(inputTypes).row(null, null, tableCommitContextForStatsPage, 6).build().get(0));
operator.addInput(rowPagesBuilder(inputTypes).row(null, null, tableCommitContextForStatsPage, 7).build().get(0));
byte[] tableCommitContextForFragmentsPage = getTableCommitContextBytes(Lifespan.taskWide(), 0, 0, NO_COMMIT, true);
operator.addInput(rowPagesBuilder(inputTypes).row(4, new byte[] { 1 }, tableCommitContextForFragmentsPage, null).build().get(0));
operator.addInput(rowPagesBuilder(inputTypes).row(5, new byte[] { 2 }, tableCommitContextForFragmentsPage, null).build().get(0));
assertThat(driverContext.getSystemMemoryUsage()).isGreaterThan(0);
assertEquals(driverContext.getMemoryUsage(), 0);
assertTrue(operator.isBlocked().isDone());
assertTrue(operator.needsInput());
operator.finish();
assertFalse(operator.isFinished());
assertNull(operator.getOutput());
List<Type> outputTypes = ImmutableList.of(BIGINT);
assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(9).build().get(0));
assertTrue(operator.isBlocked().isDone());
assertFalse(operator.needsInput());
assertTrue(operator.isFinished());
operator.close();
assertEquals(tableFinisher.getFragments(), ImmutableList.of(Slices.wrappedBuffer(new byte[] { 1 }), Slices.wrappedBuffer(new byte[] { 2 })));
assertEquals(tableFinisher.getComputedStatistics().size(), 1);
assertEquals(getOnlyElement(tableFinisher.getComputedStatistics()).getColumnStatistics().size(), 1);
Block expectedStatisticsBlock = new LongArrayBlockBuilder(null, 1).writeLong(7).closeEntry().build();
assertBlockEquals(BIGINT, getOnlyElement(tableFinisher.getComputedStatistics()).getColumnStatistics().get(statisticMetadata), expectedStatisticsBlock);
TableFinishInfo tableFinishInfo = operator.getInfo();
assertThat(tableFinishInfo.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0);
assertThat(tableFinishInfo.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
assertTrue(pageSinkCommitter.getCommittedFragments().isEmpty());
assertEquals(driverContext.getSystemMemoryUsage(), 0);
assertEquals(driverContext.getMemoryUsage(), 0);
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestTopNRowNumberOperator method testUnPartitioned.
@Test(dataProvider = "partial")
public void testUnPartitioned(boolean partial) {
List<Page> input = rowPagesBuilder(BIGINT, DOUBLE).row(1L, 0.3).row(2L, 0.2).row(3L, 0.1).row(3L, 0.91).pageBreak().row(1L, 0.4).pageBreak().row(1L, 0.5).row(1L, 0.6).row(2L, 0.7).row(2L, 0.8).pageBreak().row(2L, 0.9).build();
TopNRowNumberOperatorFactory operatorFactory = new TopNRowNumberOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), Ints.asList(), ImmutableList.of(), Ints.asList(1), ImmutableList.of(SortOrder.ASC_NULLS_LAST), 3, partial, Optional.empty(), 10, joinCompiler);
MaterializedResult expected;
if (partial) {
expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT).row(0.1, 3L).row(0.2, 2L).row(0.3, 1L).build();
} else {
expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT).row(0.1, 3L, 1L).row(0.2, 2L, 2L).row(0.3, 1L, 3L).build();
}
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestTopNRowNumberOperator method testPartitioned.
@Test(dataProvider = "hashEnabledValues")
public void testPartitioned(boolean hashEnabled) {
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, Ints.asList(0), BIGINT, DOUBLE);
List<Page> input = rowPagesBuilder.row(1L, 0.3).row(2L, 0.2).row(3L, 0.1).row(3L, 0.91).pageBreak().row(1L, 0.4).pageBreak().row(1L, 0.5).row(1L, 0.6).row(2L, 0.7).row(2L, 0.8).pageBreak().row(2L, 0.9).build();
TopNRowNumberOperatorFactory operatorFactory = new TopNRowNumberOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BIGINT, DOUBLE), Ints.asList(1, 0), Ints.asList(0), ImmutableList.of(BIGINT), Ints.asList(1), ImmutableList.of(SortOrder.ASC_NULLS_LAST), 3, false, Optional.empty(), 10, joinCompiler);
MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT).row(0.3, 1L, 1L).row(0.4, 1L, 2L).row(0.5, 1L, 3L).row(0.2, 2L, 1L).row(0.7, 2L, 2L).row(0.8, 2L, 3L).row(0.1, 3L, 1L).row(0.91, 3L, 2L).build();
assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestNestedLoopJoinOperator method newJoinOperatorFactoryWithCompletedBuild.
private static NestedLoopJoinOperatorFactory newJoinOperatorFactoryWithCompletedBuild(TaskContext taskContext, RowPagesBuilder buildPages) {
DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
ValuesOperatorFactory valuesOperatorFactory = new ValuesOperatorFactory(0, new PlanNodeId("test"), buildPages.build());
JoinBridgeManager<NestedLoopJoinBridge> nestedLoopJoinBridgeManager = new JoinBridgeManager<>(false, PipelineExecutionStrategy.UNGROUPED_EXECUTION, PipelineExecutionStrategy.UNGROUPED_EXECUTION, NestedLoopJoinPagesSupplier::new, buildPages.getTypes());
NestedLoopBuildOperatorFactory nestedLoopBuildOperatorFactory = new NestedLoopBuildOperatorFactory(1, new PlanNodeId("test"), nestedLoopJoinBridgeManager);
NestedLoopJoinOperatorFactory joinOperatorFactory = new NestedLoopJoinOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinBridgeManager);
Operator valuesOperator = valuesOperatorFactory.createOperator(driverContext);
Operator nestedLoopBuildOperator = nestedLoopBuildOperatorFactory.createOperator(driverContext);
Driver driver = Driver.createDriver(driverContext, valuesOperator, nestedLoopBuildOperator);
valuesOperatorFactory.noMoreOperators();
nestedLoopBuildOperatorFactory.noMoreOperators();
while (nestedLoopBuildOperator.isBlocked().isDone()) {
driver.process();
}
return joinOperatorFactory;
}
use of com.facebook.presto.spi.plan.PlanNodeId in project presto by prestodb.
the class TestNestedLoopBuildOperator method testNestedLoopBuildNoBlock.
@Test
public void testNestedLoopBuildNoBlock() throws Exception {
TaskContext taskContext = createTaskContext();
List<Type> buildTypes = ImmutableList.of();
JoinBridgeManager<NestedLoopJoinBridge> nestedLoopJoinBridgeManager = new JoinBridgeManager<>(false, PipelineExecutionStrategy.UNGROUPED_EXECUTION, PipelineExecutionStrategy.UNGROUPED_EXECUTION, NestedLoopJoinPagesSupplier::new, buildTypes);
NestedLoopBuildOperatorFactory nestedLoopBuildOperatorFactory = new NestedLoopBuildOperatorFactory(3, new PlanNodeId("test"), nestedLoopJoinBridgeManager);
DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
NestedLoopBuildOperator nestedLoopBuildOperator = (NestedLoopBuildOperator) nestedLoopBuildOperatorFactory.createOperator(driverContext);
NestedLoopJoinBridge nestedLoopJoinBridge = nestedLoopJoinBridgeManager.getJoinBridge(Lifespan.taskWide());
assertFalse(nestedLoopJoinBridge.getPagesFuture().isDone());
// build pages
Page buildPage1 = new Page(3);
Page buildPageEmpty = new Page(0);
Page buildPage2 = new Page(3000);
nestedLoopBuildOperator.addInput(buildPage1);
nestedLoopBuildOperator.addInput(buildPageEmpty);
nestedLoopBuildOperator.addInput(buildPage2);
nestedLoopBuildOperator.finish();
assertTrue(nestedLoopJoinBridge.getPagesFuture().isDone());
List<Page> buildPages = nestedLoopJoinBridge.getPagesFuture().get().getPages();
assertEquals(buildPages.size(), 1);
assertEquals(buildPages.get(0).getPositionCount(), 3003);
}
Aggregations