use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult in project presto by prestodb.
the class TestDomainTranslator method testFromUnprocessableComparison.
@Test
public void testFromUnprocessableComparison() throws Exception {
// If it is not a simple comparison, we should not try to process it
Expression predicate = comparison(GREATER_THAN, unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT));
ExtractionResult result = fromPredicate(predicate);
assertEquals(result.getRemainingExpression(), predicate);
assertTrue(result.getTupleDomain().isAll());
// Complement
predicate = not(comparison(GREATER_THAN, unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT)));
result = fromPredicate(predicate);
assertEquals(result.getRemainingExpression(), predicate);
assertTrue(result.getTupleDomain().isAll());
}
use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult in project presto by prestodb.
the class TestDomainTranslator method testFromBasicComparisonsWithNulls.
@Test
public void testFromBasicComparisonsWithNulls() throws Exception {
// Test out the extraction of all basic comparisons with null literals
Expression originalExpression = greaterThan(C_BIGINT, nullLiteral(BIGINT));
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = greaterThan(C_VARCHAR, nullLiteral(VARCHAR));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_VARCHAR, Domain.create(ValueSet.none(VARCHAR), false))));
originalExpression = greaterThanOrEqual(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = lessThan(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = lessThanOrEqual(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = equal(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = equal(C_COLOR, nullLiteral(COLOR));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = notEqual(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = notEqual(C_COLOR, nullLiteral(COLOR));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = isDistinctFrom(C_BIGINT, nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
originalExpression = isDistinctFrom(C_COLOR, nullLiteral(COLOR));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.notNull(COLOR))));
// Test complements
originalExpression = not(greaterThan(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(greaterThanOrEqual(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(lessThan(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(lessThanOrEqual(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(equal(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(equal(C_COLOR, nullLiteral(COLOR)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(notEqual(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(notEqual(C_COLOR, nullLiteral(COLOR)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(isDistinctFrom(C_BIGINT, nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT))));
originalExpression = not(isDistinctFrom(C_COLOR, nullLiteral(COLOR)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.onlyNull(COLOR))));
}
use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult in project presto by prestodb.
the class TestDomainTranslator method testRoundTrip.
@Test
public void testRoundTrip() throws Exception {
TupleDomain<Symbol> tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).put(C_BOOLEAN, Domain.singleValue(BOOLEAN, true)).put(C_BIGINT_1, Domain.singleValue(BIGINT, 2L)).put(C_DOUBLE_1, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(DOUBLE, 1.1), Range.equal(DOUBLE, 2.0), Range.range(DOUBLE, 3.0, false, 3.5, true)), true)).put(C_VARCHAR_1, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(VARCHAR, utf8Slice("2013-01-01")), Range.greaterThan(VARCHAR, utf8Slice("2013-10-01"))), false)).put(C_TIMESTAMP, Domain.singleValue(TIMESTAMP, TIMESTAMP_VALUE)).put(C_DATE, Domain.singleValue(DATE, DATE_VALUE)).put(C_COLOR, Domain.singleValue(COLOR, COLOR_VALUE_1)).put(C_HYPER_LOG_LOG, Domain.notNull(HYPER_LOG_LOG)).build());
ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), tupleDomain);
}
use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult in project presto by prestodb.
the class TestDomainTranslator method testFromIsNullPredicate.
@Test
public void testFromIsNullPredicate() throws Exception {
Expression originalExpression = isNull(C_BIGINT);
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT))));
originalExpression = isNull(C_HYPER_LOG_LOG);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.onlyNull(HYPER_LOG_LOG))));
originalExpression = not(isNull(C_BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
originalExpression = not(isNull(C_HYPER_LOG_LOG));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.notNull(HYPER_LOG_LOG))));
}
Aggregations