Search in sources :

Example 21 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class TestSchedulingOrderVisitor method testSemiJoinOrder.

@Test
public void testSemiJoinOrder() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), METADATA);
    VariableReferenceExpression sourceJoin = planBuilder.variable("sourceJoin");
    TableScanNode a = planBuilder.tableScan(ImmutableList.of(sourceJoin), ImmutableMap.of(sourceJoin, new TestingColumnHandle("sourceJoin")));
    VariableReferenceExpression filteringSource = planBuilder.variable("filteringSource");
    TableScanNode b = planBuilder.tableScan(ImmutableList.of(filteringSource), ImmutableMap.of(filteringSource, new TestingColumnHandle("filteringSource")));
    List<PlanNodeId> order = scheduleOrder(planBuilder.semiJoin(sourceJoin, filteringSource, planBuilder.variable("semiJoinOutput"), Optional.empty(), Optional.empty(), a, b));
    assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.spi.TestingColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 22 with PlanNodeIdAllocator

use of com.facebook.presto.spi.plan.PlanNodeIdAllocator in project presto by prestodb.

the class AddIntermediateAggregations method apply.

@Override
public Result apply(AggregationNode aggregation, Captures captures, Context context) {
    Lookup lookup = context.getLookup();
    PlanNodeIdAllocator idAllocator = context.getIdAllocator();
    Session session = context.getSession();
    TypeProvider types = context.getVariableAllocator().getTypes();
    Optional<PlanNode> rewrittenSource = recurseToPartial(lookup.resolve(aggregation.getSource()), lookup, idAllocator, types);
    if (!rewrittenSource.isPresent()) {
        return Result.empty();
    }
    PlanNode source = rewrittenSource.get();
    if (getTaskConcurrency(session) > 1) {
        Map<VariableReferenceExpression, Aggregation> variableToAggregations = inputsAsOutputs(aggregation.getAggregations(), types);
        if (variableToAggregations.isEmpty()) {
            return Result.empty();
        }
        source = roundRobinExchange(idAllocator.getNextId(), LOCAL, source);
        source = new AggregationNode(aggregation.getSourceLocation(), idAllocator.getNextId(), source, variableToAggregations, aggregation.getGroupingSets(), aggregation.getPreGroupedVariables(), INTERMEDIATE, aggregation.getHashVariable(), aggregation.getGroupIdVariable());
        source = gatheringExchange(idAllocator.getNextId(), LOCAL, source);
    }
    return Result.ofPlanNode(aggregation.replaceChildren(ImmutableList.of(source)));
}
Also used : Aggregation(com.facebook.presto.spi.plan.AggregationNode.Aggregation) PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) Lookup(com.facebook.presto.sql.planner.iterative.Lookup) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) Session(com.facebook.presto.Session)

Aggregations

PlanNodeIdAllocator (com.facebook.presto.spi.plan.PlanNodeIdAllocator)22 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)14 Test (org.testng.annotations.Test)9 PlanVariableAllocator (com.facebook.presto.sql.planner.PlanVariableAllocator)7 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)5 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)4 ProjectionContext (com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext)4 Session (com.facebook.presto.Session)3 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)3 ConnectorId (com.facebook.presto.spi.ConnectorId)3 TableHandle (com.facebook.presto.spi.TableHandle)3 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)3 TpchColumnHandle (com.facebook.presto.tpch.TpchColumnHandle)3 TpchTableHandle (com.facebook.presto.tpch.TpchTableHandle)3 BeforeClass (org.testng.annotations.BeforeClass)3 Capture (com.facebook.presto.matching.Capture)2 Capture.newCapture (com.facebook.presto.matching.Capture.newCapture)2 Captures (com.facebook.presto.matching.Captures)2 Pattern (com.facebook.presto.matching.Pattern)2