Search in sources :

Example 81 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestMemo method testInitialization.

@Test
public void testInitialization() throws Exception {
    PlanNode plan = node(node());
    Memo memo = new Memo(idAllocator, plan);
    assertEquals(memo.getGroupCount(), 2);
    assertMatchesStructure(plan, memo.extract());
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Test(org.testng.annotations.Test)

Example 82 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class RuleAssert method matches.

public void matches(PlanMatchPattern pattern) {
    SymbolAllocator symbolAllocator = new SymbolAllocator(symbols);
    Optional<PlanNode> result = rule.apply(plan, x -> x, idAllocator, symbolAllocator);
    if (!result.isPresent()) {
        fail(String.format("%s did not fire for:\n%s", rule.getClass().getName(), PlanPrinter.textLogicalPlan(plan, symbolAllocator.getTypes(), metadata, session, 2)));
    }
    PlanNode actual = result.get();
    if (actual == plan) {
        // plans are not comparable, so we can only ensure they are not the same instance
        fail(String.format("%s: rule fired but return the original plan:\n%s", rule.getClass().getName(), PlanPrinter.textLogicalPlan(plan, symbolAllocator.getTypes(), metadata, session, 2)));
    }
    if (!ImmutableSet.copyOf(plan.getOutputSymbols()).equals(ImmutableSet.copyOf(actual.getOutputSymbols()))) {
        fail(String.format("%s: output schema of transformed and original plans are not equivalent\n" + "\texpected: %s\n" + "\tactual:   %s", rule.getClass().getName(), plan.getOutputSymbols(), actual.getOutputSymbols()));
    }
    assertPlan(session, metadata, new Plan(actual, symbolAllocator), pattern);
}
Also used : SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) PlanAssert.assertPlan(com.facebook.presto.sql.planner.assertions.PlanAssert.assertPlan) Plan(com.facebook.presto.sql.planner.Plan)

Example 83 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class RuleAssert method doesNotFire.

public void doesNotFire() {
    SymbolAllocator symbolAllocator = new SymbolAllocator(symbols);
    Optional<PlanNode> result = rule.apply(plan, x -> x, idAllocator, symbolAllocator);
    if (result.isPresent()) {
        fail(String.format("Expected %s to not fire for:\n%s", rule.getClass().getName(), PlanPrinter.textLogicalPlan(plan, symbolAllocator.getTypes(), metadata, session, 2)));
    }
}
Also used : SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode)

Example 84 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestEliminateCrossJoins method testJoinOrder.

@Test
public void testJoinOrder() {
    PlanNode plan = join(join(values(symbol("a")), values(symbol("b"))), values(symbol("c")), symbol("a"), symbol("c"), symbol("c"), symbol("b"));
    JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
    assertEquals(EliminateCrossJoins.getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) JoinGraph(com.facebook.presto.sql.planner.optimizations.joins.JoinGraph) Test(org.testng.annotations.Test)

Example 85 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestEliminateCrossJoins method testJoinOrderWithRealCrossJoin.

@Test
public void testJoinOrderWithRealCrossJoin() {
    PlanNode leftPlan = join(join(values(symbol("a")), values(symbol("b"))), values(symbol("c")), symbol("a"), symbol("c"), symbol("c"), symbol("b"));
    PlanNode rightPlan = join(join(values(symbol("x")), values(symbol("y"))), values(symbol("z")), symbol("x"), symbol("z"), symbol("z"), symbol("y"));
    PlanNode plan = join(leftPlan, rightPlan);
    JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
    assertEquals(EliminateCrossJoins.getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1, 3, 5, 4));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) JoinGraph(com.facebook.presto.sql.planner.optimizations.joins.JoinGraph) Test(org.testng.annotations.Test)

Aggregations

PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)89 Test (org.testng.annotations.Test)41 Expression (com.facebook.presto.sql.tree.Expression)28 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)18 Symbol (com.facebook.presto.sql.planner.Symbol)12 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)12 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)12 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)12 ImmutableList (com.google.common.collect.ImmutableList)12 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 FilterNode (com.facebook.presto.sql.planner.plan.FilterNode)9 LimitNode (com.facebook.presto.sql.planner.plan.LimitNode)9 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)9 Signature (com.facebook.presto.metadata.Signature)7 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)7 List (java.util.List)7 JoinGraph (com.facebook.presto.sql.planner.optimizations.joins.JoinGraph)6 ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)6 Session (com.facebook.presto.Session)5