use of com.facebook.presto.sql.tree.Relation in project presto by prestodb.
the class PredicateStitcher method visitTable.
@Override
protected Node visitTable(Table table, PredicateStitcherContext context) {
SchemaTableName schemaTableName = toSchemaTableName(createQualifiedObjectName(session, table, table.getName()));
if (!predicates.containsKey(schemaTableName)) {
return table;
}
QuerySpecification queryWithPredicateStitching = new QuerySpecification(selectList(new AllColumns()), Optional.of(table), Optional.of(predicates.get(schemaTableName)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
Relation subquery = subquery(new Query(Optional.empty(), queryWithPredicateStitching, Optional.empty(), Optional.empty(), Optional.empty()));
if (context.isCreateAlias()) {
return new AliasedRelation(subquery, identifier(schemaTableName.getTableName()), null);
}
return subquery;
}
use of com.facebook.presto.sql.tree.Relation in project presto by prestodb.
the class PredicateStitcher method visitExcept.
@Override
protected Node visitExcept(Except node, PredicateStitcherContext context) {
Relation rewrittenLeft = (Relation) process(node.getLeft(), context);
Relation rewrittenRight = (Relation) process(node.getRight(), context);
return new Except(rewrittenLeft, rewrittenRight, node.isDistinct());
}
use of com.facebook.presto.sql.tree.Relation 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