Search in sources :

Example 6 with LimitNode

use of com.facebook.presto.sql.planner.plan.LimitNode 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 7 with LimitNode

use of com.facebook.presto.sql.planner.plan.LimitNode 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 8 with LimitNode

use of com.facebook.presto.sql.planner.plan.LimitNode 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)

Example 9 with LimitNode

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

the class MergeLimits 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 LimitNode)) {
        return Optional.empty();
    }
    LimitNode child = (LimitNode) source;
    return Optional.of(new LimitNode(parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), parent.isPartial()));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode)

Aggregations

LimitNode (com.facebook.presto.sql.planner.plan.LimitNode)9 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)8 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)2 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)2 TopNNode (com.facebook.presto.sql.planner.plan.TopNNode)2 PrestoException (com.facebook.presto.spi.PrestoException)1 Symbol (com.facebook.presto.sql.planner.Symbol)1 ApplyNode (com.facebook.presto.sql.planner.plan.ApplyNode)1 DistinctLimitNode (com.facebook.presto.sql.planner.plan.DistinctLimitNode)1 MarkDistinctNode (com.facebook.presto.sql.planner.plan.MarkDistinctNode)1 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)1 SortNode (com.facebook.presto.sql.planner.plan.SortNode)1 TableFinishNode (com.facebook.presto.sql.planner.plan.TableFinishNode)1 TableWriterNode (com.facebook.presto.sql.planner.plan.TableWriterNode)1 Cast (com.facebook.presto.sql.tree.Cast)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 ExistsPredicate (com.facebook.presto.sql.tree.ExistsPredicate)1 Expression (com.facebook.presto.sql.tree.Expression)1 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)1 ArrayList (java.util.ArrayList)1