Search in sources :

Example 11 with PlanNode

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

the class RelationPlanner method visitExcept.

@Override
protected RelationPlan visitExcept(Except node, Void context) {
    checkArgument(!node.getRelations().isEmpty(), "No relations specified for EXCEPT");
    SetOperationPlan setOperationPlan = process(node);
    PlanNode planNode = new ExceptNode(idAllocator.getNextId(), setOperationPlan.getSources(), setOperationPlan.getSymbolMapping(), ImmutableList.copyOf(setOperationPlan.getSymbolMapping().keySet()));
    return new RelationPlan(planNode, analysis.getScope(node), planNode.getOutputSymbols());
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ExceptNode(com.facebook.presto.sql.planner.plan.ExceptNode)

Example 12 with PlanNode

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

the class MergeFilters method apply.

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

Example 13 with PlanNode

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

the class PushLimitThroughMarkDistinct 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 child = lookup.resolve(parent.getSource());
    if (!(child instanceof MarkDistinctNode)) {
        return Optional.empty();
    }
    return Optional.of(transpose(parent, child));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) MarkDistinctNode(com.facebook.presto.sql.planner.plan.MarkDistinctNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode)

Example 14 with PlanNode

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

the class PushLimitThroughProject 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 child = lookup.resolve(parent.getSource());
    if (!(child instanceof ProjectNode)) {
        return Optional.empty();
    }
    return Optional.of(transpose(parent, child));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode)

Example 15 with PlanNode

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

the class JoinGraph method joinWith.

private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinClauses, Context context, PlanNodeId newRoot) {
    for (PlanNode node : other.nodes) {
        checkState(!edges.containsKey(node.getId()), format("Node [%s] appeared in two JoinGraphs", node));
    }
    List<PlanNode> nodes = ImmutableList.<PlanNode>builder().addAll(this.nodes).addAll(other.nodes).build();
    ImmutableMultimap.Builder<PlanNodeId, Edge> edges = ImmutableMultimap.<PlanNodeId, Edge>builder().putAll(this.edges).putAll(other.edges);
    List<Expression> joinedFilters = ImmutableList.<Expression>builder().addAll(this.filters).addAll(other.filters).build();
    for (JoinNode.EquiJoinClause edge : joinClauses) {
        Symbol leftSymbol = edge.getLeft();
        Symbol rightSymbol = edge.getRight();
        checkState(context.containsSymbol(leftSymbol));
        checkState(context.containsSymbol(rightSymbol));
        PlanNode left = context.getSymbolSource(leftSymbol);
        PlanNode right = context.getSymbolSource(rightSymbol);
        edges.put(left.getId(), new Edge(right, leftSymbol, rightSymbol));
        edges.put(right.getId(), new Edge(left, rightSymbol, leftSymbol));
    }
    return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty());
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) Symbol(com.facebook.presto.sql.planner.Symbol) ImmutableMultimap(com.google.common.collect.ImmutableMultimap)

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