use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.
the class CanonicalPlanGenerator method visitProject.
@Override
public Optional<PlanNode> visitProject(ProjectNode node, Map<VariableReferenceExpression, VariableReferenceExpression> context) {
Optional<PlanNode> source = node.getSource().accept(this, context);
if (!source.isPresent()) {
return Optional.empty();
}
List<RowExpressionReference> rowExpressionReferences = node.getAssignments().entrySet().stream().map(entry -> new RowExpressionReference(inlineVariables(context, entry.getValue()), entry.getKey())).sorted(comparing(rowExpressionReference -> rowExpressionReference.getRowExpression().toString())).collect(toImmutableList());
ImmutableMap.Builder<VariableReferenceExpression, RowExpression> assignments = ImmutableMap.builder();
for (RowExpressionReference rowExpressionReference : rowExpressionReferences) {
VariableReferenceExpression reference = variableAllocator.newVariable(rowExpressionReference.getRowExpression());
context.put(rowExpressionReference.getVariableReferenceExpression(), reference);
assignments.put(reference, rowExpressionReference.getRowExpression());
}
return Optional.of(new ProjectNode(node.getSourceLocation(), planNodeidAllocator.getNextId(), source.get(), new Assignments(assignments.build()), node.getLocality()));
}
use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.
the class TestPruneAggregationColumns method buildProjectedAggregation.
private ProjectNode buildProjectedAggregation(PlanBuilder planBuilder, Predicate<VariableReferenceExpression> projectionFilter) {
VariableReferenceExpression a = planBuilder.variable("a");
VariableReferenceExpression b = planBuilder.variable("b");
VariableReferenceExpression key = planBuilder.variable("key");
return planBuilder.project(identityAssignmentsAsSymbolReferences(ImmutableList.of(a, b).stream().filter(projectionFilter).collect(toImmutableSet())), planBuilder.aggregation(aggregationBuilder -> aggregationBuilder.source(planBuilder.values(key)).singleGroupingSet(key).addAggregation(a, planBuilder.expression("count()"), ImmutableList.of()).addAggregation(b, planBuilder.expression("count()"), ImmutableList.of())));
}
use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.
the class TestRuleIndex method testWithPlanNodeHierarchy.
@Test
public void testWithPlanNodeHierarchy() {
Rule projectRule1 = new NoOpRule(Pattern.typeOf(ProjectNode.class));
Rule projectRule2 = new NoOpRule(Pattern.typeOf(ProjectNode.class));
Rule filterRule = new NoOpRule(Pattern.typeOf(FilterNode.class));
Rule anyRule = new NoOpRule(Pattern.any());
RuleIndex ruleIndex = RuleIndex.builder().register(projectRule1).register(projectRule2).register(filterRule).register(anyRule).build();
ProjectNode projectNode = planBuilder.project(Assignments.of(), planBuilder.values());
FilterNode filterNode = planBuilder.filter(BooleanLiteral.TRUE_LITERAL, planBuilder.values());
ValuesNode valuesNode = planBuilder.values();
assertEquals(ruleIndex.getCandidates(projectNode).collect(toSet()), ImmutableSet.of(projectRule1, projectRule2, anyRule));
assertEquals(ruleIndex.getCandidates(filterNode).collect(toSet()), ImmutableSet.of(filterRule, anyRule));
assertEquals(ruleIndex.getCandidates(valuesNode).collect(toSet()), ImmutableSet.of(anyRule));
}
use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.
the class TestTypeValidator method testValidProject.
@Test
public void testValidProject() {
Expression expression1 = new Cast(new SymbolReference(variableB.getName()), StandardTypes.BIGINT);
Expression expression2 = new Cast(new SymbolReference(variableC.getName()), StandardTypes.BIGINT);
Assignments assignments = Assignments.builder().put(variableAllocator.newVariable(expression1, BIGINT), castToRowExpression(expression1)).put(variableAllocator.newVariable(expression2, BIGINT), castToRowExpression(expression2)).build();
PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
assertTypesValid(node);
}
use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.
the class TestTypeValidator method testInvalidProject.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of variable 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
public void testInvalidProject() {
Expression expression1 = new Cast(new SymbolReference(variableB.getName()), StandardTypes.INTEGER);
Expression expression2 = new Cast(new SymbolReference(variableA.getName()), StandardTypes.INTEGER);
Assignments assignments = Assignments.builder().put(variableAllocator.newVariable(expression1, BIGINT), // should be INTEGER
castToRowExpression(expression1)).put(variableAllocator.newVariable(expression1, INTEGER), castToRowExpression(expression2)).build();
PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
assertTypesValid(node);
}
Aggregations