Search in sources :

Example 1 with ValuesNode

use of com.facebook.presto.sql.planner.plan.ValuesNode in project presto by prestodb.

the class TestCountConstantOptimizer method testCountConstantOptimizer.

@Test
public void testCountConstantOptimizer() throws Exception {
    CountConstantOptimizer optimizer = new CountConstantOptimizer();
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    Symbol countAggregationSymbol = new Symbol("count");
    Signature countAggregationSignature = new Signature("count", FunctionKind.AGGREGATE, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT));
    ImmutableMap<Symbol, FunctionCall> aggregations = ImmutableMap.of(countAggregationSymbol, new FunctionCall(QualifiedName.of("count"), ImmutableList.of(new SymbolReference("expr"))));
    ImmutableMap<Symbol, Signature> functions = ImmutableMap.of(countAggregationSymbol, countAggregationSignature);
    ValuesNode valuesNode = new ValuesNode(planNodeIdAllocator.getNextId(), ImmutableList.of(new Symbol("col")), ImmutableList.of(ImmutableList.of()));
    AggregationNode eligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new LongLiteral("42"))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
    assertTrue(((AggregationNode) optimizer.optimize(eligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
    AggregationNode ineligiblePlan = new AggregationNode(planNodeIdAllocator.getNextId(), new ProjectNode(planNodeIdAllocator.getNextId(), valuesNode, Assignments.of(new Symbol("expr"), new FunctionCall(QualifiedName.of("function"), ImmutableList.of(new Identifier("x"))))), aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of()), AggregationNode.Step.INTERMEDIATE, Optional.empty(), Optional.empty());
    assertFalse(((AggregationNode) optimizer.optimize(ineligiblePlan, TEST_SESSION, ImmutableMap.of(), new SymbolAllocator(), new PlanNodeIdAllocator())).getAggregations().get(countAggregationSymbol).getArguments().isEmpty());
}
Also used : SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Symbol(com.facebook.presto.sql.planner.Symbol) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) Identifier(com.facebook.presto.sql.tree.Identifier) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 2 with ValuesNode

use of com.facebook.presto.sql.planner.plan.ValuesNode in project presto by prestodb.

the class TestSimplifyExpressions method simplifyExpressions.

private static Expression simplifyExpressions(Expression expression) {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    FilterNode filterNode = new FilterNode(planNodeIdAllocator.getNextId(), new ValuesNode(planNodeIdAllocator.getNextId(), emptyList(), emptyList()), expression);
    FilterNode simplifiedNode = (FilterNode) SIMPLIFIER.optimize(filterNode, TEST_SESSION, booleanSymbolTypeMapFor(expression), new SymbolAllocator(), planNodeIdAllocator);
    return simplifiedNode.getPredicate();
}
Also used : SymbolAllocator(com.facebook.presto.sql.planner.SymbolAllocator) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) FilterNode(com.facebook.presto.sql.planner.plan.FilterNode)

Example 3 with ValuesNode

use of com.facebook.presto.sql.planner.plan.ValuesNode in project presto by prestodb.

the class QueryPlanner method planImplicitTable.

private RelationPlan planImplicitTable(QuerySpecification node) {
    List<Expression> emptyRow = ImmutableList.of();
    Scope scope = Scope.builder().withParent(analysis.getScope(node)).build();
    return new RelationPlan(new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow)), scope, ImmutableList.of());
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) Scope(com.facebook.presto.sql.analyzer.Scope) Expression(com.facebook.presto.sql.tree.Expression)

Example 4 with ValuesNode

use of com.facebook.presto.sql.planner.plan.ValuesNode in project presto by prestodb.

the class PruneValuesColumns method apply.

@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
    if (!(node instanceof ProjectNode)) {
        return Optional.empty();
    }
    ProjectNode parent = (ProjectNode) node;
    PlanNode child = lookup.resolve(parent.getSource());
    if (!(child instanceof ValuesNode)) {
        return Optional.empty();
    }
    ValuesNode values = (ValuesNode) child;
    Optional<List<Symbol>> dependencies = pruneInputs(child.getOutputSymbols(), parent.getAssignments().getExpressions());
    if (!dependencies.isPresent()) {
        return Optional.empty();
    }
    List<Symbol> newOutputs = dependencies.get();
    // for each output of project, the corresponding column in the values node
    int[] mapping = new int[newOutputs.size()];
    for (int i = 0; i < mapping.length; i++) {
        mapping[i] = values.getOutputSymbols().indexOf(newOutputs.get(i));
    }
    ImmutableList.Builder<List<Expression>> rowsBuilder = ImmutableList.builder();
    for (List<Expression> row : values.getRows()) {
        rowsBuilder.add(Arrays.stream(mapping).mapToObj(row::get).collect(Collectors.toList()));
    }
    return Optional.of(new ProjectNode(parent.getId(), new ValuesNode(values.getId(), newOutputs, rowsBuilder.build()), parent.getAssignments()));
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) Symbol(com.facebook.presto.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 5 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)6 Symbol (com.facebook.presto.sql.planner.Symbol)3 PlanNodeIdAllocator (com.facebook.presto.sql.planner.PlanNodeIdAllocator)2 SymbolAllocator (com.facebook.presto.sql.planner.SymbolAllocator)2 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)2 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)2 Expression (com.facebook.presto.sql.tree.Expression)2 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)2 Signature (com.facebook.presto.metadata.Signature)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 Scope (com.facebook.presto.sql.analyzer.Scope)1 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)1 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)1 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)1 DeleteNode (com.facebook.presto.sql.planner.plan.DeleteNode)1 ExchangeNode (com.facebook.presto.sql.planner.plan.ExchangeNode)1 FilterNode (com.facebook.presto.sql.planner.plan.FilterNode)1 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)1 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)1 TableFinishNode (com.facebook.presto.sql.planner.plan.TableFinishNode)1