use of com.facebook.presto.sql.planner.plan.ExchangeNode 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