use of io.prestosql.sql.planner.plan.DeleteNode in project hetu-core by openlookeng.
the class QueryPlanner method plan.
public DeleteNode plan(Delete node) {
Table table = node.getTable();
TableHandle handle = analysis.getTableHandle(table);
RelationPlan relationPlan = new RelationPlanner(analysis, planSymbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, metadata, session, namedSubPlan, uniqueIdAllocator).process(table, null);
PlanBuilder builder = planBuilderFor(relationPlan);
if (node.getWhere().isPresent()) {
builder = filter(builder, node.getWhere().get(), node);
}
// create delete node
Symbol rowId = builder.translate(analysis.getRowIdField(table));
List<Symbol> outputs = ImmutableList.of(planSymbolAllocator.newSymbol("partialrows", BIGINT), planSymbolAllocator.newSymbol("fragment", VARBINARY));
return new DeleteNode(idAllocator.getNextId(), builder.getRoot(), new DeleteTarget(handle, metadata.getTableMetadata(session, handle).getTable()), rowId, outputs);
}
use of io.prestosql.sql.planner.plan.DeleteNode in project hetu-core by openlookeng.
the class LogicalPlanner method createDeletePlan.
private RelationPlan createDeletePlan(Analysis analysis, Delete node) {
TableHandle handle = analysis.getTableHandle(node.getTable());
if (handle.getConnectorHandle().isDeleteAsInsertSupported()) {
QueryPlanner.UpdateDeleteRelationPlan deletePlan = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).planDeleteRowAsInsert(node);
RelationPlan plan = deletePlan.getPlan();
Optional<NewTableLayout> newTableLayout = metadata.getUpdateLayout(session, handle);
TableMetadata tableMetadata = metadata.getTableMetadata(session, handle);
String catalogName = handle.getCatalogName().getCatalogName();
Optional<Expression> constraint = deletePlan.getPredicate().isPresent() ? Optional.of(OriginalExpressionUtils.castToExpression(deletePlan.getPredicate().get())) : Optional.empty();
// Skip statistics collection for delete,
// because stats collection for delete seems to corrupt existing statistics
TableStatisticsMetadata statisticsMetadata = TableStatisticsMetadata.empty();
return createTableWriterPlan(analysis, plan, new TableWriterNode.DeleteAsInsertReference(handle, constraint, deletePlan.getColumnAssignments()), deletePlan.getColumNames(), newTableLayout, statisticsMetadata);
} else {
DeleteNode deleteNode = new QueryPlanner(analysis, planSymbolAllocator, idAllocator, buildLambdaDeclarationToSymbolMap(analysis, planSymbolAllocator), metadata, session, namedSubPlan, uniqueIdAllocator).plan(node);
TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), deleteNode, deleteNode.getTarget(), planSymbolAllocator.newSymbol("rows", BIGINT), Optional.empty(), Optional.empty());
return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputSymbols());
}
}
Aggregations