Search in sources :

Example 36 with PlanNode

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()))));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Test(org.testng.annotations.Test)

Example 37 with PlanNode

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));
}
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 38 with PlanNode

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));
}
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 39 with PlanNode

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);
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) Symbol(com.facebook.presto.sql.planner.Symbol) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 40 with PlanNode

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);
}
Also used : SortItem(com.facebook.presto.sql.tree.SortItem) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) Expression(com.facebook.presto.sql.tree.Expression) SortNode(com.facebook.presto.sql.planner.plan.SortNode) ImmutableList(com.google.common.collect.ImmutableList) SortOrder(com.facebook.presto.spi.block.SortOrder) TopNNode(com.facebook.presto.sql.planner.plan.TopNNode)

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