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