Search in sources :

Example 1 with RowExpressionNodeInliner

use of com.facebook.presto.expressions.RowExpressionNodeInliner in project presto by prestodb.

the class EqualityInference method rewriteExpression.

private RowExpression rewriteExpression(RowExpression expression, Predicate<VariableReferenceExpression> variableScope, boolean allowFullReplacement) {
    Iterable<RowExpression> subExpressions = uniqueSubExpressions(expression);
    if (!allowFullReplacement) {
        subExpressions = filter(subExpressions, not(equalTo(expression)));
    }
    ImmutableMap.Builder<RowExpression, RowExpression> expressionRemap = ImmutableMap.builder();
    for (RowExpression subExpression : subExpressions) {
        RowExpression canonical = getScopedCanonical(subExpression, variableScope);
        if (canonical != null) {
            expressionRemap.put(subExpression, canonical);
        }
    }
    // Perform a naive single-pass traversal to try to rewrite non-compliant portions of the tree. Prefers to replace
    // larger subtrees over smaller subtrees
    // TODO: this rewrite can probably be made more sophisticated
    RowExpression rewritten = RowExpressionTreeRewriter.rewriteWith(new RowExpressionNodeInliner(expressionRemap.build()), expression);
    if (!variableToExpressionPredicate(variableScope).apply(rewritten)) {
        // If the rewritten is still not compliant with the symbol scope, just give up
        return null;
    }
    return rewritten;
}
Also used : RowExpressionNodeInliner(com.facebook.presto.expressions.RowExpressionNodeInliner) RowExpression(com.facebook.presto.spi.relation.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

RowExpressionNodeInliner (com.facebook.presto.expressions.RowExpressionNodeInliner)1 RowExpression (com.facebook.presto.spi.relation.RowExpression)1 ImmutableMap (com.google.common.collect.ImmutableMap)1