Search in sources :

Example 1 with DeleteNode

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);
}
Also used : DeleteNode(io.prestosql.sql.planner.plan.DeleteNode) Table(io.prestosql.sql.tree.Table) Symbol(io.prestosql.spi.plan.Symbol) TableHandle(io.prestosql.spi.metadata.TableHandle) DeleteTarget(io.prestosql.sql.planner.plan.TableWriterNode.DeleteTarget)

Example 2 with DeleteNode

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());
    }
}
Also used : TableMetadata(io.prestosql.metadata.TableMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) TableStatisticsMetadata(io.prestosql.spi.statistics.TableStatisticsMetadata) NewTableLayout(io.prestosql.metadata.NewTableLayout) TableFinishNode(io.prestosql.sql.planner.plan.TableFinishNode) DeleteNode(io.prestosql.sql.planner.plan.DeleteNode) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) IfExpression(io.prestosql.sql.tree.IfExpression) TableHandle(io.prestosql.spi.metadata.TableHandle) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode)

Aggregations

TableHandle (io.prestosql.spi.metadata.TableHandle)2 DeleteNode (io.prestosql.sql.planner.plan.DeleteNode)2 NewTableLayout (io.prestosql.metadata.NewTableLayout)1 TableMetadata (io.prestosql.metadata.TableMetadata)1 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)1 Symbol (io.prestosql.spi.plan.Symbol)1 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)1 TableStatisticsMetadata (io.prestosql.spi.statistics.TableStatisticsMetadata)1 TableFinishNode (io.prestosql.sql.planner.plan.TableFinishNode)1 TableWriterNode (io.prestosql.sql.planner.plan.TableWriterNode)1 DeleteTarget (io.prestosql.sql.planner.plan.TableWriterNode.DeleteTarget)1 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)1 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)1 Expression (io.prestosql.sql.tree.Expression)1 IfExpression (io.prestosql.sql.tree.IfExpression)1 Table (io.prestosql.sql.tree.Table)1