use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestMemo method testInsertNode.
/*
From: X -> Z
To: X -> Y -> Z
*/
@Test
public void testInsertNode() throws Exception {
PlanNode z = node();
PlanNode x = node(z);
Memo memo = new Memo(idAllocator, x);
assertEquals(memo.getGroupCount(), 2);
int zGroup = getChildGroup(memo, memo.getRootGroup());
PlanNode y = node(memo.getNode(zGroup));
memo.replace(zGroup, y, "rule");
assertEquals(memo.getGroupCount(), 3);
assertMatchesStructure(memo.extract(), node(x.getId(), node(y.getId(), node(z.getId()))));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestEliminateCrossJoins method testDoNotReorderCrossJoins.
@Test
public void testDoNotReorderCrossJoins() {
PlanNode plan = join(join(values(symbol("a")), values(symbol("b"))), values(symbol("c")), symbol("c"), symbol("b"));
JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
assertEquals(EliminateCrossJoins.getJoinOrder(joinGraph), ImmutableList.of(0, 1, 2));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestEliminateCrossJoins method testDonNotChangeOrderWithoutCrossJoin.
@Test
public void testDonNotChangeOrderWithoutCrossJoin() {
PlanNode plan = join(join(values(symbol("a")), values(symbol("b")), symbol("a"), symbol("b")), values(symbol("c")), symbol("c"), symbol("b"));
JoinGraph joinGraph = getOnlyElement(JoinGraph.buildFrom(plan));
assertEquals(EliminateCrossJoins.getJoinOrder(joinGraph), ImmutableList.of(0, 1, 2));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class TestVerifyOnlyOneOutputNode method testValidateFailed.
@Test(expectedExceptions = IllegalStateException.class)
public void testValidateFailed() throws Exception {
// random plan with 2 output nodes
PlanNode root = new OutputNode(idAllocator.getNextId(), new ExplainAnalyzeNode(idAllocator.getNextId(), new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of()), new Symbol("a")), ImmutableList.of(), ImmutableList.of());
new VerifyOnlyOneOutputNode().validate(root, null, null, null, null);
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class QueryPlanner method sort.
private PlanBuilder sort(PlanBuilder subPlan, Optional<OrderBy> orderBy, Optional<String> limit, List<Expression> orderByExpressions) {
if (!orderBy.isPresent()) {
return subPlan;
}
Iterator<SortItem> sortItems = orderBy.get().getSortItems().iterator();
ImmutableList.Builder<Symbol> orderBySymbols = ImmutableList.builder();
Map<Symbol, SortOrder> orderings = new HashMap<>();
for (Expression fieldOrExpression : orderByExpressions) {
Symbol symbol = subPlan.translate(fieldOrExpression);
SortItem sortItem = sortItems.next();
if (!orderings.containsKey(symbol)) {
orderBySymbols.add(symbol);
orderings.put(symbol, toSortOrder(sortItem));
}
}
PlanNode planNode;
if (limit.isPresent() && !limit.get().equalsIgnoreCase("all")) {
planNode = new TopNNode(idAllocator.getNextId(), subPlan.getRoot(), Long.parseLong(limit.get()), orderBySymbols.build(), orderings, false);
} else {
planNode = new SortNode(idAllocator.getNextId(), subPlan.getRoot(), orderBySymbols.build(), orderings);
}
return subPlan.withNewRoot(planNode);
}
Aggregations