Search in sources :

Example 1 with TableFinishNode

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

Example 2 with TableFinishNode

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

the class LogicalPlanner method createDeletePlan.

private RelationPlan createDeletePlan(Analysis analysis, Delete node) {
    DeleteNode deleteNode = new QueryPlanner(analysis, symbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, symbolAllocator), metadata, session).plan(node);
    List<Symbol> outputs = ImmutableList.of(symbolAllocator.newSymbol("rows", BIGINT));
    TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), deleteNode, deleteNode.getTarget(), outputs);
    return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputSymbols());
}
Also used : DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode)

Example 3 with TableFinishNode

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

the class RemoveEmptyDelete method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof TableFinishNode)) {
        return Optional.empty();
    }
    TableFinishNode finish = (TableFinishNode) node;
    PlanNode finishSource = lookup.resolve(finish.getSource());
    if (!(finishSource instanceof ExchangeNode)) {
        return Optional.empty();
    }
    ExchangeNode exchange = (ExchangeNode) finishSource;
    if (exchange.getSources().size() != 1) {
        return Optional.empty();
    }
    PlanNode exchangeSource = lookup.resolve(getOnlyElement(exchange.getSources()));
    if (!(exchangeSource instanceof DeleteNode)) {
        return Optional.empty();
    }
    DeleteNode delete = (DeleteNode) exchangeSource;
    PlanNode deleteSource = lookup.resolve(delete.getSource());
    if (!(deleteSource instanceof ValuesNode)) {
        return Optional.empty();
    }
    ValuesNode values = (ValuesNode) deleteSource;
    if (!values.getRows().isEmpty()) {
        return Optional.empty();
    }
    return Optional.of(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of(ImmutableList.of(new LongLiteral("0")))));
}
Also used : DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode)

Aggregations

TableFinishNode (com.facebook.presto.sql.planner.plan.TableFinishNode)3 DeleteNode (com.facebook.presto.sql.planner.plan.DeleteNode)2 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)2 PrestoException (com.facebook.presto.spi.PrestoException)1 ExchangeNode (com.facebook.presto.sql.planner.plan.ExchangeNode)1 LimitNode (com.facebook.presto.sql.planner.plan.LimitNode)1 TableWriterNode (com.facebook.presto.sql.planner.plan.TableWriterNode)1 ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)1 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)1 ArrayList (java.util.ArrayList)1