Search in sources :

Example 16 with PlanNodeIdAllocator

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

the class TestPlanRemoteProjections method testLocalOnly.

@Test
void testLocalOnly() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    planBuilder.variable("x", INTEGER);
    planBuilder.variable("y", INTEGER);
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("abs(x) + abs(y)")).put(planBuilder.variable("b", BOOLEAN), planBuilder.rowExpression("x is null and y is null")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 1);
    assertEquals(rewritten.get(0).getProjections().size(), 2);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 17 with PlanNodeIdAllocator

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

the class TestPlanRemoteProjections method testRemoteAndLocal.

@Test
void testRemoteAndLocal() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), getMetadata());
    planBuilder.variable("x", INTEGER);
    planBuilder.variable("y", INTEGER);
    PlanRemotePojections rule = new PlanRemotePojections(getFunctionAndTypeManager());
    List<ProjectionContext> rewritten = rule.planRemoteAssignments(Assignments.builder().put(planBuilder.variable("a"), planBuilder.rowExpression("unittest.memory.remote_foo(x, y + unittest.memory.remote_foo(x))")).put(planBuilder.variable("b"), planBuilder.rowExpression("abs(x)")).put(planBuilder.variable("c"), planBuilder.rowExpression("abs(unittest.memory.remote_foo())")).put(planBuilder.variable("d"), planBuilder.rowExpression("unittest.memory.remote_foo(x + y, abs(x))")).build(), new PlanVariableAllocator(planBuilder.getTypes().allVariables()));
    assertEquals(rewritten.size(), 4);
    assertEquals(rewritten.get(3).getProjections().size(), 4);
}
Also used : ProjectionContext(com.facebook.presto.sql.planner.iterative.rule.PlanRemotePojections.ProjectionContext) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 18 with PlanNodeIdAllocator

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

the class TestJoinEnumerator method testDoesNotCreateJoinWhenPartitionedOnCrossJoin.

@Test
public void testDoesNotCreateJoinWhenPartitionedOnCrossJoin() {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = new PlanBuilder(TEST_SESSION, idAllocator, queryRunner.getMetadata());
    VariableReferenceExpression a1 = p.variable("A1");
    VariableReferenceExpression b1 = p.variable("B1");
    MultiJoinNode multiJoinNode = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(p.values(a1), p.values(b1))), TRUE_CONSTANT, ImmutableList.of(a1, b1));
    JoinEnumerator joinEnumerator = new JoinEnumerator(new CostComparator(1, 1, 1), multiJoinNode.getFilter(), createContext(), determinismEvaluator, functionResolution, metadata);
    JoinEnumerationResult actual = joinEnumerator.createJoinAccordingToPartitioning(multiJoinNode.getSources(), multiJoinNode.getOutputVariables(), ImmutableSet.of(0));
    assertFalse(actual.getPlanNode().isPresent());
    assertEquals(actual.getCost(), PlanCostEstimate.infinite());
}
Also used : CostComparator(com.facebook.presto.cost.CostComparator) JoinEnumerator(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.JoinEnumerator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) JoinEnumerationResult(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.JoinEnumerationResult) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(com.facebook.presto.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) Test(org.testng.annotations.Test)

Example 19 with PlanNodeIdAllocator

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

the class TestJoinEnumerator method createContext.

private Rule.Context createContext() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanVariableAllocator variableAllocator = new PlanVariableAllocator();
    CachingStatsProvider statsProvider = new CachingStatsProvider(queryRunner.getStatsCalculator(), Optional.empty(), noLookup(), queryRunner.getDefaultSession(), variableAllocator.getTypes());
    CachingCostProvider costProvider = new CachingCostProvider(queryRunner.getCostCalculator(), statsProvider, Optional.empty(), queryRunner.getDefaultSession());
    return new Rule.Context() {

        @Override
        public Lookup getLookup() {
            return noLookup();
        }

        @Override
        public PlanNodeIdAllocator getIdAllocator() {
            return planNodeIdAllocator;
        }

        @Override
        public PlanVariableAllocator getVariableAllocator() {
            return variableAllocator;
        }

        @Override
        public Session getSession() {
            return queryRunner.getDefaultSession();
        }

        @Override
        public StatsProvider getStatsProvider() {
            return statsProvider;
        }

        @Override
        public CostProvider getCostProvider() {
            return costProvider;
        }

        @Override
        public void checkTimeoutNotExhausted() {
        }

        @Override
        public WarningCollector getWarningCollector() {
            return WarningCollector.NOOP;
        }
    };
}
Also used : CachingStatsProvider(com.facebook.presto.cost.CachingStatsProvider) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) CachingCostProvider(com.facebook.presto.cost.CachingCostProvider) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator)

Example 20 with PlanNodeIdAllocator

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

the class TestSchedulingOrderVisitor method testJoinOrder.

@Test
public void testJoinOrder() {
    PlanBuilder planBuilder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), METADATA);
    TableScanNode a = planBuilder.tableScan(emptyList(), emptyMap());
    TableScanNode b = planBuilder.tableScan(emptyList(), emptyMap());
    List<PlanNodeId> order = scheduleOrder(planBuilder.join(JoinNode.Type.INNER, a, b));
    assertEquals(order, ImmutableList.of(b.getId(), a.getId()));
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

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