use of com.facebook.presto.spi.relation.SpecialFormExpression.Form.OR in project presto by prestodb.
the class RowExpressionDomainTranslator method extractDisjuncts.
private List<RowExpression> extractDisjuncts(Type type, DiscreteValues discreteValues, RowExpression reference) {
List<RowExpression> values = discreteValues.getValues().stream().map(object -> toRowExpression(reference.getSourceLocation(), object, type)).collect(toList());
// If values is empty, then the equatableValues was either ALL or NONE, both of which should already have been checked for
checkState(!values.isEmpty());
RowExpression predicate;
if (values.size() == 1) {
predicate = equal(reference, getOnlyElement(values));
} else {
predicate = in(reference, values);
}
if (!discreteValues.isWhiteList()) {
predicate = not(functionResolution, predicate);
}
return ImmutableList.of(predicate);
}
use of com.facebook.presto.spi.relation.SpecialFormExpression.Form.OR in project presto by prestodb.
the class TestLogicalRowExpressions method testBigExpressions.
@Test
public void testBigExpressions() {
// Do not expand big list (a0 && b0) || (a1 && b1) || ....
RowExpression bigExpression = or(IntStream.range(0, 1000).boxed().map(i -> and(name("a" + i), name("b" + i))).toArray(RowExpression[]::new));
assertEquals(logicalRowExpressions.convertToConjunctiveNormalForm(bigExpression), bigExpression);
// extract common predicates on (a && b0) || (a && b1) || ....
RowExpression bigExpressionWithCommonPredicate = or(IntStream.range(0, 10001).boxed().map(i -> and(name("a"), name("b" + i))).toArray(RowExpression[]::new));
assertEquals(logicalRowExpressions.convertToConjunctiveNormalForm(bigExpressionWithCommonPredicate), or(IntStream.range(0, 10001).boxed().map(i -> and(name("a"), name("b" + i))).toArray(RowExpression[]::new)));
// a || (a && b0) || (a && b1) || ... can be simplified to a but if conjunctive is very large, we will skip reduction.
assertEquals(logicalRowExpressions.convertToConjunctiveNormalForm(or(a, bigExpressionWithCommonPredicate)), or(Stream.concat(Stream.of(name("a")), IntStream.range(0, 10001).boxed().map(i -> and(name("a"), name("b" + i)))).toArray(RowExpression[]::new)));
assertEquals(logicalRowExpressions.convertToDisjunctiveNormalForm(or(a, bigExpressionWithCommonPredicate)), or(Stream.concat(Stream.of(name("a")), IntStream.range(0, 10001).boxed().map(i -> and(name("a"), name("b" + i)))).toArray(RowExpression[]::new)));
}
Aggregations