Search in sources :

Example 56 with PlanNodeId

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);
}
Also used : TableFinishOperatorFactory(com.facebook.presto.operator.TableFinishOperator.TableFinishOperatorFactory) ColumnStatisticMetadata(com.facebook.presto.spi.statistics.ColumnStatisticMetadata) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) Block(com.facebook.presto.common.block.Block) LongArrayBlockBuilder(com.facebook.presto.common.block.LongArrayBlockBuilder) StatisticAggregationsDescriptor(com.facebook.presto.sql.planner.plan.StatisticAggregationsDescriptor) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 57 with PlanNodeId

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Page(com.facebook.presto.common.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) TopNRowNumberOperatorFactory(com.facebook.presto.operator.TopNRowNumberOperator.TopNRowNumberOperatorFactory) Test(org.testng.annotations.Test)

Example 58 with PlanNodeId

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.common.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) TopNRowNumberOperatorFactory(com.facebook.presto.operator.TopNRowNumberOperator.TopNRowNumberOperatorFactory) Test(org.testng.annotations.Test)

Example 59 with PlanNodeId

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;
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) NestedLoopBuildOperatorFactory(com.facebook.presto.operator.NestedLoopBuildOperator.NestedLoopBuildOperatorFactory) ValuesOperatorFactory(com.facebook.presto.operator.ValuesOperator.ValuesOperatorFactory) NestedLoopJoinOperatorFactory(com.facebook.presto.operator.NestedLoopJoinOperator.NestedLoopJoinOperatorFactory)

Example 60 with PlanNodeId

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);
}
Also used : TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) Page(com.facebook.presto.common.Page) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) Type(com.facebook.presto.common.type.Type) NestedLoopBuildOperatorFactory(com.facebook.presto.operator.NestedLoopBuildOperator.NestedLoopBuildOperatorFactory) Test(org.testng.annotations.Test)

Aggregations

PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)204 Test (org.testng.annotations.Test)123 Page (com.facebook.presto.common.Page)83 MaterializedResult (com.facebook.presto.testing.MaterializedResult)52 Type (com.facebook.presto.common.type.Type)47 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)43 ImmutableList (com.google.common.collect.ImmutableList)43 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)39 DataSize (io.airlift.units.DataSize)39 Optional (java.util.Optional)35 ImmutableMap (com.google.common.collect.ImmutableMap)34 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)25 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)23 VariableStatsEstimate (com.facebook.presto.cost.VariableStatsEstimate)23 Split (com.facebook.presto.metadata.Split)23 OperatorFactory (com.facebook.presto.operator.OperatorFactory)23 PlanNodeStatsEstimate (com.facebook.presto.cost.PlanNodeStatsEstimate)22 RowExpression (com.facebook.presto.spi.relation.RowExpression)21 PlanMatchPattern.values (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values)21 JOIN_DISTRIBUTION_TYPE (com.facebook.presto.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)20