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;
}
Aggregations