Search in sources :

Example 51 with PlanNode

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

the class Memo method replace.

public PlanNode replace(int group, PlanNode node, String reason) {
    PlanNode old = membership.get(group);
    checkArgument(new HashSet<>(old.getOutputSymbols()).equals(new HashSet<>(node.getOutputSymbols())), "%s: transformed expression doesn't produce same outputs: %s vs %s", reason, old.getOutputSymbols(), node.getOutputSymbols());
    if (node instanceof GroupReference) {
        node = getNode(((GroupReference) node).getGroupId());
    } else {
        node = insertChildrenAndRewrite(node);
    }
    incrementReferenceCounts(node);
    membership.put(group, node);
    decrementReferenceCounts(old);
    return node;
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) HashSet(java.util.HashSet)

Example 52 with PlanNode

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

the class Memo method insertRecursive.

private int insertRecursive(PlanNode node) {
    if (node instanceof GroupReference) {
        return ((GroupReference) node).getGroupId();
    }
    int group = nextGroupId();
    PlanNode rewritten = insertChildrenAndRewrite(node);
    membership.put(group, rewritten);
    referenceCounts.put(group, 0);
    incrementReferenceCounts(rewritten);
    return group;
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode)

Example 53 with PlanNode

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

the class MergeLimitWithDistinct method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof LimitNode)) {
        return Optional.empty();
    }
    LimitNode parent = (LimitNode) node;
    PlanNode input = lookup.resolve(parent.getSource());
    if (!(input instanceof AggregationNode)) {
        return Optional.empty();
    }
    AggregationNode child = (AggregationNode) input;
    if (isDistinct(child)) {
        return Optional.empty();
    }
    return Optional.of(new DistinctLimitNode(parent.getId(), child.getSource(), parent.getCount(), false, child.getHashSymbol()));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) DistinctLimitNode(com.facebook.presto.sql.planner.plan.DistinctLimitNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) DistinctLimitNode(com.facebook.presto.sql.planner.plan.DistinctLimitNode) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode)

Example 54 with PlanNode

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

the class MergeLimitWithSort method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof LimitNode)) {
        return Optional.empty();
    }
    LimitNode parent = (LimitNode) node;
    PlanNode source = lookup.resolve(parent.getSource());
    if (!(source instanceof SortNode)) {
        return Optional.empty();
    }
    SortNode child = (SortNode) source;
    return Optional.of(new TopNNode(parent.getId(), child.getSource(), parent.getCount(), child.getOrderBy(), child.getOrderings(), parent.isPartial()));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) SortNode(com.facebook.presto.sql.planner.plan.SortNode) TopNNode(com.facebook.presto.sql.planner.plan.TopNNode)

Example 55 with PlanNode

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

the class MergeLimitWithTopN method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof LimitNode)) {
        return Optional.empty();
    }
    LimitNode parent = (LimitNode) node;
    PlanNode source = lookup.resolve(parent.getSource());
    if (!(source instanceof TopNNode)) {
        return Optional.empty();
    }
    TopNNode child = (TopNNode) source;
    return Optional.of(new TopNNode(parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), child.getOrderBy(), child.getOrderings(), parent.isPartial()));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) 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