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