Search in sources :

Example 1 with LimitNode

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

the class PushLimitThroughSemiJoin 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 SemiJoinNode)) {
        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) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode)

Example 2 with LimitNode

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

the class TransformExistsApplyToScalarApply method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof ApplyNode)) {
        return Optional.empty();
    }
    ApplyNode parent = (ApplyNode) node;
    if (parent.getSubqueryAssignments().size() != 1) {
        return Optional.empty();
    }
    Expression expression = getOnlyElement(parent.getSubqueryAssignments().getExpressions());
    if (!(expression instanceof ExistsPredicate)) {
        return Optional.empty();
    }
    Symbol count = symbolAllocator.newSymbol(COUNT.toString(), BIGINT);
    Symbol exists = getOnlyElement(parent.getSubqueryAssignments().getSymbols());
    return Optional.of(new ApplyNode(node.getId(), parent.getInput(), new ProjectNode(idAllocator.getNextId(), new AggregationNode(idAllocator.getNextId(), new LimitNode(idAllocator.getNextId(), parent.getSubquery(), 1, false), ImmutableMap.of(count, COUNT_CALL), ImmutableMap.of(count, countSignature), ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()), Assignments.of(exists, new ComparisonExpression(GREATER_THAN, count.toSymbolReference(), new Cast(new LongLiteral("0"), BIGINT.toString())))), Assignments.of(exists, exists.toSymbolReference()), parent.getCorrelation()));
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Symbol(com.facebook.presto.sql.planner.Symbol) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) ExistsPredicate(com.facebook.presto.sql.tree.ExistsPredicate) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode)

Example 3 with LimitNode

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

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

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

the class LogicalPlanner method createTableWriterPlan.

private RelationPlan createTableWriterPlan(Analysis analysis, RelationPlan plan, WriterTarget target, List<String> columnNames, Optional<NewTableLayout> writeTableLayout) {
    List<Symbol> writerOutputs = ImmutableList.of(symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY));
    PlanNode source = plan.getRoot();
    if (!analysis.isCreateTableAsSelectWithData()) {
        source = new LimitNode(idAllocator.getNextId(), source, 0L, false);
    }
    // todo this should be checked in analysis
    writeTableLayout.ifPresent(layout -> {
        if (!ImmutableSet.copyOf(columnNames).containsAll(layout.getPartitionColumns())) {
            throw new PrestoException(NOT_SUPPORTED, "INSERT must write all distribution columns: " + layout.getPartitionColumns());
        }
    });
    List<Symbol> symbols = plan.getFieldMappings();
    Optional<PartitioningScheme> partitioningScheme = Optional.empty();
    if (writeTableLayout.isPresent()) {
        List<Symbol> partitionFunctionArguments = new ArrayList<>();
        writeTableLayout.get().getPartitionColumns().stream().mapToInt(columnNames::indexOf).mapToObj(symbols::get).forEach(partitionFunctionArguments::add);
        List<Symbol> outputLayout = new ArrayList<>(symbols);
        partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(writeTableLayout.get().getPartitioning(), partitionFunctionArguments), outputLayout));
    }
    PlanNode writerNode = new TableWriterNode(idAllocator.getNextId(), source, target, symbols, columnNames, writerOutputs, partitioningScheme);
    List<Symbol> outputs = ImmutableList.of(symbolAllocator.newSymbol("rows", BIGINT));
    TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), writerNode, target, outputs);
    return new RelationPlan(commitNode, analysis.getRootScope(), outputs);
}
Also used : ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) LimitNode(com.facebook.presto.sql.planner.plan.LimitNode) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode)

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