Search in sources :

Example 91 with Expression

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);
    }
}
Also used : DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Expression(com.facebook.presto.sql.tree.Expression)

Example 92 with Expression

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);
}
Also used : FieldReference(com.facebook.presto.sql.tree.FieldReference) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Expression(com.facebook.presto.sql.tree.Expression)

Example 93 with Expression

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;
}
Also used : DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Expression(com.facebook.presto.sql.tree.Expression)

Example 94 with Expression

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()));
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) Symbol(com.facebook.presto.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 95 with Expression

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;
}
Also used : Expression(com.facebook.presto.sql.tree.Expression) Symbol(com.facebook.presto.sql.planner.Symbol) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) Map(java.util.Map)

Aggregations

Expression (com.facebook.presto.sql.tree.Expression)137 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)74 Test (org.testng.annotations.Test)46 NotExpression (com.facebook.presto.sql.tree.NotExpression)42 InListExpression (com.facebook.presto.sql.tree.InListExpression)40 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)33 Type (com.facebook.presto.spi.type.Type)26 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)26 LiteralInterpreter.toExpression (com.facebook.presto.sql.planner.LiteralInterpreter.toExpression)25 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)22 ImmutableList (com.google.common.collect.ImmutableList)22 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)19 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)18 Cast (com.facebook.presto.sql.tree.Cast)17 ArrayList (java.util.ArrayList)17 ExtractionResult (com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult)16 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)16 SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)16 SubscriptExpression (com.facebook.presto.sql.tree.SubscriptExpression)16 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)15