Search in sources :

Example 11 with ValuesNode

use of com.facebook.presto.sql.planner.plan.ValuesNode 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")))));
}
Also used : DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode)

Aggregations

ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)11 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)5 Expression (com.facebook.presto.sql.tree.Expression)5 Symbol (com.facebook.presto.sql.planner.Symbol)4 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)4 Scope (com.facebook.presto.sql.analyzer.Scope)3 OutputNode (com.facebook.presto.sql.planner.plan.OutputNode)3 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Test (org.testng.annotations.Test)3 Field (com.facebook.presto.sql.analyzer.Field)2 ExpressionInterpreter.evaluateConstantExpression (com.facebook.presto.sql.planner.ExpressionInterpreter.evaluateConstantExpression)2 PlanNodeIdAllocator (com.facebook.presto.sql.planner.PlanNodeIdAllocator)2 SymbolAllocator (com.facebook.presto.sql.planner.SymbolAllocator)2 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)2 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)2 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)2 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)2 ArrayList (java.util.ArrayList)2 Signature (com.facebook.presto.metadata.Signature)1