use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEqualityInference method testTransitivity.
@Test
public void testTransitivity() throws Exception {
EqualityInference.Builder builder = new EqualityInference.Builder();
addEquality("a1", "b1", builder);
addEquality("b1", "c1", builder);
addEquality("d1", "c1", builder);
addEquality("a2", "b2", builder);
addEquality("b2", "a2", builder);
addEquality("b2", "c2", builder);
addEquality("d2", "b2", builder);
addEquality("c2", "d2", builder);
EqualityInference inference = builder.build();
assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesSymbols("d1", "d2")), someExpression("d1", "d2"));
assertEquals(inference.rewriteExpression(someExpression("a1", "c1"), matchesSymbols("b1")), someExpression("b1", "b1"));
assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesSymbols("b1", "d2", "c3")), someExpression("b1", "d2"));
// Both starting expressions should canonicalize to the same expression
assertEquals(inference.getScopedCanonical(nameReference("a2"), matchesSymbols("c2", "d2")), inference.getScopedCanonical(nameReference("b2"), matchesSymbols("c2", "d2")));
Expression canonical = inference.getScopedCanonical(nameReference("a2"), matchesSymbols("c2", "d2"));
// Given multiple translatable candidates, should choose the canonical
assertEquals(inference.rewriteExpression(someExpression("a2", "b2"), matchesSymbols("c2", "d2")), someExpression(canonical, canonical));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestEqualityInference method testTriviallyRewritable.
@Test
public void testTriviallyRewritable() throws Exception {
EqualityInference.Builder builder = new EqualityInference.Builder();
Expression expression = builder.build().rewriteExpression(someExpression("a1", "a2"), matchesSymbols("a1", "a2"));
assertEquals(expression, someExpression("a1", "a2"));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromBetweenPredicate.
@Test
public void testFromBetweenPredicate() throws Exception {
Expression originalExpression = between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L));
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 2L, true)), false))));
originalExpression = between(cast(C_BIGINT, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 2L, true)), false))));
originalExpression = between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
// Test complements
originalExpression = not(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 2L)), false))));
originalExpression = not(between(cast(C_BIGINT, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 2L)), false))));
originalExpression = not(between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L)), false))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromBooleanLiteralPredicate.
@Test
public void testFromBooleanLiteralPredicate() throws Exception {
Expression originalExpression = TRUE_LITERAL;
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isAll());
originalExpression = not(TRUE_LITERAL);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = FALSE_LITERAL;
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(FALSE_LITERAL);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isAll());
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromIsNotNullPredicate.
@Test
public void testFromIsNotNullPredicate() throws Exception {
Expression originalExpression = isNotNull(C_BIGINT);
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
originalExpression = isNotNull(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))));
originalExpression = not(isNotNull(C_BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT))));
originalExpression = not(isNotNull(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))));
}
Aggregations