use of com.facebook.presto.spi.plan.ValuesNode 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.ValuesNode in project presto by prestodb.
the class RelationPlanner method visitUnnest.
@Override
protected RelationPlan visitUnnest(Unnest node, Void context) {
Scope scope = analysis.getScope(node);
ImmutableList.Builder<VariableReferenceExpression> outputVariablesBuilder = ImmutableList.builder();
for (Field field : scope.getRelationType().getVisibleFields()) {
VariableReferenceExpression variable = variableAllocator.newVariable(field);
outputVariablesBuilder.add(variable);
}
List<VariableReferenceExpression> unnestedVariables = outputVariablesBuilder.build();
// If we got here, then we must be unnesting a constant, and not be in a join (where there could be column references)
ImmutableList.Builder<VariableReferenceExpression> argumentVariables = ImmutableList.builder();
ImmutableList.Builder<RowExpression> values = ImmutableList.builder();
ImmutableMap.Builder<VariableReferenceExpression, List<VariableReferenceExpression>> unnestVariables = ImmutableMap.builder();
Iterator<VariableReferenceExpression> unnestedVariablesIterator = unnestedVariables.iterator();
for (Expression expression : node.getExpressions()) {
Type type = analysis.getType(expression);
Expression rewritten = Coercer.addCoercions(expression, analysis);
rewritten = ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), rewritten);
values.add(castToRowExpression(rewritten));
VariableReferenceExpression input = variableAllocator.newVariable(rewritten, type);
argumentVariables.add(new VariableReferenceExpression(getSourceLocation(rewritten), input.getName(), type));
if (type instanceof ArrayType) {
Type elementType = ((ArrayType) type).getElementType();
if (!SystemSessionProperties.isLegacyUnnest(session) && elementType instanceof RowType) {
ImmutableList.Builder<VariableReferenceExpression> unnestVariableBuilder = ImmutableList.builder();
for (int i = 0; i < ((RowType) elementType).getFields().size(); i++) {
unnestVariableBuilder.add(unnestedVariablesIterator.next());
}
unnestVariables.put(input, unnestVariableBuilder.build());
} else {
unnestVariables.put(input, ImmutableList.of(unnestedVariablesIterator.next()));
}
} else if (type instanceof MapType) {
unnestVariables.put(input, ImmutableList.of(unnestedVariablesIterator.next(), unnestedVariablesIterator.next()));
} else {
throw new IllegalArgumentException("Unsupported type for UNNEST: " + type);
}
}
Optional<VariableReferenceExpression> ordinalityVariable = node.isWithOrdinality() ? Optional.of(unnestedVariablesIterator.next()) : Optional.empty();
checkState(!unnestedVariablesIterator.hasNext(), "Not all output variables were matched with input variables");
ValuesNode valuesNode = new ValuesNode(getSourceLocation(node), idAllocator.getNextId(), argumentVariables.build(), ImmutableList.of(values.build()));
UnnestNode unnestNode = new UnnestNode(getSourceLocation(node), idAllocator.getNextId(), valuesNode, ImmutableList.of(), unnestVariables.build(), ordinalityVariable);
return new RelationPlan(unnestNode, scope, unnestedVariables);
}
use of com.facebook.presto.spi.plan.ValuesNode in project presto by prestodb.
the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.
@Test
public void testValidateSuccessful() {
// random seemingly valid plan
PlanNode root = new OutputNode(Optional.empty(), idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(Optional.empty(), idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of());
new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Aggregations