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());
}
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);
}
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)));
}
}
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));
}
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));
}
Aggregations