use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TranslationMap method addIntermediateMapping.
public void addIntermediateMapping(Expression expression, Expression rewritten) {
if (rewritten.equals(expression)) {
return;
}
Expression translated = translateNamesToSymbols(expression);
if (expressionToExpressions.containsKey(translated)) {
Expression previousMapping = expressionToExpressions.get(translated);
if (!previousMapping.equals(rewritten)) {
put(expression, rewritten);
addIntermediateMapping(rewritten, previousMapping);
}
} else {
put(expression, rewritten);
}
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TranslationMap method get.
public Symbol get(Expression expression) {
if (expression instanceof FieldReference) {
int field = ((FieldReference) expression).getFieldIndex();
checkArgument(fieldSymbols[field] != null, "No mapping for field: %s", field);
return fieldSymbols[field];
}
Expression translated = translateNamesToSymbols(expression);
if (!expressionToSymbols.containsKey(translated)) {
checkArgument(expressionToExpressions.containsKey(translated), "No mapping for expression: %s", expression);
return get(expressionToExpressions.get(translated));
}
return expressionToSymbols.get(translated);
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TranslationMap method getMapping.
private Expression getMapping(Expression expression) {
if (!expressionToExpressions.containsKey(expression)) {
return expression;
}
Expression mapped = expressionToExpressions.get(expression);
Expression translated = translateNamesToSymbols(mapped);
if (!translated.equals(expression) && expressionToExpressions.containsKey(translated)) {
mapped = getMapping(translated);
}
return mapped;
}
use of com.facebook.presto.sql.tree.Expression 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.tree.Expression in project presto by prestodb.
the class ProjectNode method isIdentity.
public boolean isIdentity() {
for (Map.Entry<Symbol, Expression> entry : assignments.entrySet()) {
Expression expression = entry.getValue();
Symbol symbol = entry.getKey();
if (!(expression instanceof SymbolReference && ((SymbolReference) expression).getName().equals(symbol.getName()))) {
return false;
}
}
return true;
}
Aggregations