use of com.facebook.presto.sql.tree.SetOperation in project presto by prestodb.
the class RelationPlanner method process.
private SetOperationPlan process(SetOperation node) {
List<VariableReferenceExpression> outputs = null;
ImmutableList.Builder<PlanNode> sources = ImmutableList.builder();
ImmutableListMultimap.Builder<VariableReferenceExpression, VariableReferenceExpression> variableMapping = ImmutableListMultimap.builder();
List<RelationPlan> subPlans = node.getRelations().stream().map(relation -> processAndCoerceIfNecessary(relation, null)).collect(toImmutableList());
for (RelationPlan relationPlan : subPlans) {
List<VariableReferenceExpression> childOutputVariables = relationPlan.getFieldMappings();
if (outputs == null) {
// Use the first Relation to derive output variable names
RelationType descriptor = relationPlan.getDescriptor();
ImmutableList.Builder<VariableReferenceExpression> outputVariableBuilder = ImmutableList.builder();
for (Field field : descriptor.getVisibleFields()) {
int fieldIndex = descriptor.indexOf(field);
VariableReferenceExpression variable = childOutputVariables.get(fieldIndex);
outputVariableBuilder.add(variableAllocator.newVariable(variable));
}
outputs = outputVariableBuilder.build();
}
RelationType descriptor = relationPlan.getDescriptor();
checkArgument(descriptor.getVisibleFieldCount() == outputs.size(), "Expected relation to have %s variables but has %s variables", descriptor.getVisibleFieldCount(), outputs.size());
int fieldId = 0;
for (Field field : descriptor.getVisibleFields()) {
int fieldIndex = descriptor.indexOf(field);
variableMapping.put(outputs.get(fieldId), childOutputVariables.get(fieldIndex));
fieldId++;
}
sources.add(relationPlan.getRoot());
}
return new SetOperationPlan(sources.build(), variableMapping.build());
}
Aggregations