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);
}
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());
}
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")))));
}
Aggregations