Make binaryExpression() handle empty list
Change ExpressionUtils.binaryExpression to return TRUE on an empty list
@@ -26,7 +26,6 @@ import com.facebook.presto.sql.tree.LambdaExpression;
import com.facebook.presto.sql.tree.LogicalBinaryExpression;
import com.facebook.presto.sql.tree.NotExpression;
import com.facebook.presto.sql.tree.SymbolReference;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -104,7 +103,17 @@ public final class ExpressionUtils
{
requireNonNull(type, "type is null");
requireNonNull(expressions, "expressions is null");
- Preconditions.checkArgument(!expressions.isEmpty(), "expressions is empty");
+
+ if (expressions.isEmpty()) {
+ switch (type) {
+ case AND:
+ return TRUE_LITERAL;
+ case OR:
+ return FALSE_LITERAL;
+ default:
+ throw new IllegalArgumentException("Unsupported LogicalBinaryExpression type");
+ }
+ }
// Build balanced tree for efficient recursive processing that
// preserves the evaluation order of the input expressions.
@@ -191,7 +200,7 @@ public final class ExpressionUtils
return FALSE_LITERAL;
}
- return conjuncts.isEmpty() ? TRUE_LITERAL : and(conjuncts);
+ return and(conjuncts);
}
public static Expression combineDisjuncts(Expression... expressions)
