Search in sources :

Example 1 with TableDeleteNode

use of io.prestosql.sql.planner.plan.TableDeleteNode in project hetu-core by openlookeng.

the class TestExternalFunctionPushDownChecker method testTableDeleteNode.

@Test
public void testTableDeleteNode() {
    PlanNode node = new TableDeleteNode(idAllocator.getNextId(), builder.values(), Optional.of(sumCall), tableHandle, ImmutableMap.of(), columnA);
    validatePlan(node);
}
Also used : TableDeleteNode(io.prestosql.sql.planner.plan.TableDeleteNode) PlanNode(io.prestosql.spi.plan.PlanNode) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Example 2 with TableDeleteNode

use of io.prestosql.sql.planner.plan.TableDeleteNode in project hetu-core by openlookeng.

the class PushDeleteAsInsertIntoConnector method apply.

@Override
public Result apply(TableFinishNode node, Captures captures, Context context) {
    if (!withFilter) {
        TableScanNode tableScan = captures.get(TABLE_SCAN);
        return metadata.applyDelete(context.getSession(), tableScan.getTable()).map(newHandle -> new TableDeleteNode(context.getIdAllocator().getNextId(), newHandle, getOnlyElement(node.getOutputSymbols()))).map(Result::ofPlanNode).orElseGet(Result::empty);
    }
    TableWriterNode writerNode = captures.get(WRITER_NODE);
    TableWriterNode.DeleteAsInsertReference deleteTargetRef = (TableWriterNode.DeleteAsInsertReference) writerNode.getTarget();
    if (!deleteTargetRef.getConstraint().isPresent()) {
        // Not expected to reach here.
        return Result.empty();
    }
    Expression predicate = deleteTargetRef.getConstraint().get();
    Expression filtered = ExpressionUtils.filterDeterministicConjuncts(predicate);
    if (!predicate.equals(filtered)) {
        // There were some non-deterministic filters.. so cannot directly delete
        return Result.empty();
    }
    Set<Symbol> allPredicateSymbols = SymbolsExtractor.extractUnique(predicate);
    Map<Symbol, ColumnHandle> columnAssignments = deleteTargetRef.getColumnAssignments();
    Set<Symbol> allColumns = columnAssignments.keySet();
    List<Symbol> predicateColumnSymbols = allPredicateSymbols.stream().filter(allColumns::contains).distinct().collect(Collectors.toList());
    // If all predicate symbols are partitionColumns, then only partition can be deleted directly.
    if (predicateColumnSymbols.isEmpty() || !predicateColumnSymbols.stream().allMatch(symbol -> {
        ColumnHandle columnHandle = columnAssignments.get(symbol);
        return columnHandle != null && columnHandle.isPartitionKey();
    })) {
        return Result.empty();
    }
    FilterNode filterNode = captures.get(FILTER);
    List<Symbol> nonTableSymbols = allPredicateSymbols.stream().filter(symbol -> !allColumns.contains(symbol)).collect(Collectors.toList());
    PredicateContext predicateContext = new PredicateContext();
    PlanNode rewrittenSource = SimplePlanRewriter.rewriteWith(new ReWriter(columnAssignments.keySet(), nonTableSymbols, context.getLookup(), logicalRowExpressions), filterNode, predicateContext);
    /**
     * Create the TableDeleteNode with source to evaluate the predicate subqueries
     */
    TableDeleteNode tableDeleteNode = new TableDeleteNode(context.getIdAllocator().getNextId(), rewrittenSource, Optional.of(predicateContext.tablePredicate), deleteTargetRef.getHandle(), deleteTargetRef.getColumnAssignments(), getOnlyElement(node.getOutputSymbols()));
    return Result.ofPlanNode(tableDeleteNode);
}
Also used : TableDeleteNode(io.prestosql.sql.planner.plan.TableDeleteNode) Pattern.typeOf(io.prestosql.matching.Pattern.typeOf) Lookup(io.prestosql.sql.planner.iterative.Lookup) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) TableFinishNode(io.prestosql.sql.planner.plan.TableFinishNode) Capture.newCapture(io.prestosql.matching.Capture.newCapture) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Patterns.tableWriterNode(io.prestosql.sql.planner.plan.Patterns.tableWriterNode) Patterns.tableFinish(io.prestosql.sql.planner.plan.Patterns.tableFinish) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) SymbolsExtractor(io.prestosql.sql.planner.SymbolsExtractor) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) Metadata(io.prestosql.metadata.Metadata) Captures(io.prestosql.matching.Captures) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) Capture(io.prestosql.matching.Capture) Optional(java.util.Optional) Patterns.source(io.prestosql.sql.planner.plan.Patterns.source) TableWriter.target(io.prestosql.sql.planner.plan.Patterns.TableWriter.target) DELETE_TRANSACTIONAL_TABLE_DIRECT(io.prestosql.SystemSessionProperties.DELETE_TRANSACTIONAL_TABLE_DIRECT) Pattern(io.prestosql.matching.Pattern) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) SimplePlanRewriter(io.prestosql.sql.planner.plan.SimplePlanRewriter) Patterns.project(io.prestosql.sql.planner.plan.Patterns.project) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) GroupReference(io.prestosql.spi.plan.GroupReference) Patterns.filter(io.prestosql.sql.planner.plan.Patterns.filter) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) RowExpression(io.prestosql.spi.relation.RowExpression) Patterns.tableScan(io.prestosql.sql.planner.plan.Patterns.tableScan) Expression(io.prestosql.sql.tree.Expression) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) TableDeleteNode(io.prestosql.sql.planner.plan.TableDeleteNode) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) TableWriterNode(io.prestosql.sql.planner.plan.TableWriterNode)

Example 3 with TableDeleteNode

use of io.prestosql.sql.planner.plan.TableDeleteNode in project hetu-core by openlookeng.

the class TestExternalFunctionPushDownChecker method testTableDeleteNodeWithExternalCall.

@Test(expectedExceptions = ExternalFunctionPushDownChecker.IllegalExternalFunctionUsageException.class, expectedExceptionsMessageRegExp = "The external function jdbc.v1.foo does not support to push down to data source for this query.")
public void testTableDeleteNodeWithExternalCall() {
    PlanNode node = new TableDeleteNode(idAllocator.getNextId(), builder.values(), Optional.of(externalFooCall1), tableHandle, ImmutableMap.of(), columnA);
    validatePlan(node);
}
Also used : TableDeleteNode(io.prestosql.sql.planner.plan.TableDeleteNode) PlanNode(io.prestosql.spi.plan.PlanNode) Test(org.testng.annotations.Test) BasePlanTest(io.prestosql.sql.planner.assertions.BasePlanTest)

Aggregations

PlanNode (io.prestosql.spi.plan.PlanNode)3 TableDeleteNode (io.prestosql.sql.planner.plan.TableDeleteNode)3 BasePlanTest (io.prestosql.sql.planner.assertions.BasePlanTest)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Session (io.prestosql.Session)1 DELETE_TRANSACTIONAL_TABLE_DIRECT (io.prestosql.SystemSessionProperties.DELETE_TRANSACTIONAL_TABLE_DIRECT)1 LogicalRowExpressions (io.prestosql.expressions.LogicalRowExpressions)1 Capture (io.prestosql.matching.Capture)1 Capture.newCapture (io.prestosql.matching.Capture.newCapture)1 Captures (io.prestosql.matching.Captures)1 Pattern (io.prestosql.matching.Pattern)1 Pattern.typeOf (io.prestosql.matching.Pattern.typeOf)1 Metadata (io.prestosql.metadata.Metadata)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 Assignments (io.prestosql.spi.plan.Assignments)1 FilterNode (io.prestosql.spi.plan.FilterNode)1 GroupReference (io.prestosql.spi.plan.GroupReference)1 JoinNode (io.prestosql.spi.plan.JoinNode)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1