Refactor filter*DeterministicConjuncts
@@ -43,6 +43,7 @@ import java.util.function.Predicate;
import static com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL;
import static com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL;
import static com.facebook.presto.sql.tree.ComparisonExpressionType.IS_DISTINCT_FROM;
+import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
@@ -228,19 +229,21 @@ public final class ExpressionUtils
public static Expression filterDeterministicConjuncts(Expression expression)
{
- List<Expression> conjuncts = extractConjuncts(expression).stream()
- .filter(DeterminismEvaluator::isDeterministic)
- .collect(toList());
-
- return combineConjuncts(conjuncts);
+ return filterConjuncts(expression, DeterminismEvaluator::isDeterministic);
}
public static Expression filterNonDeterministicConjuncts(Expression expression)
{
- return combineConjuncts(extractConjuncts(expression)
- .stream()
- .filter((conjunct) -> !DeterminismEvaluator.isDeterministic(conjunct))
- .collect(toImmutableList()));
+ return filterConjuncts(expression, not(DeterminismEvaluator::isDeterministic));
+ }
+
+ private static Expression filterConjuncts(Expression expression, Predicate<Expression> predicate)
+ {
+ List<Expression> conjuncts = extractConjuncts(expression).stream()
+ .filter(predicate)
+ .collect(toList());
+
+ return combineConjuncts(conjuncts);
}
public static Function<Expression, Expression> expressionOrNullSymbols(final Predicate<Symbol>... nullSymbolScopes)
