Search in sources :

Example 1 with ExtractionResult

use of com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult in project presto by prestodb.

the class TestExpressionDomainTranslator method testAllRoundTrip.

@Test
public void testAllRoundTrip() {
    TupleDomain<String> tupleDomain = TupleDomain.all();
    ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertEquals(result.getTupleDomain(), tupleDomain);
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 2 with ExtractionResult

use of com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult in project presto by prestodb.

the class TestExpressionDomainTranslator method assertPredicateIsAlwaysFalse.

private void assertPredicateIsAlwaysFalse(Expression expression) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertTrue(result.getTupleDomain().isNone());
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult)

Example 3 with ExtractionResult

use of com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult in project presto by prestodb.

the class TestExpressionDomainTranslator method testExpressionConstantFolding.

@Test
public void testExpressionConstantFolding() {
    Expression originalExpression = comparison(GREATER_THAN, new SymbolReference(C_VARBINARY), function("from_hex", stringLiteral("123456")));
    ExtractionResult result = fromPredicate(originalExpression);
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    Slice value = Slices.wrappedBuffer(BaseEncoding.base16().decode("123456"));
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_VARBINARY, Domain.create(ValueSet.ofRanges(Range.greaterThan(VARBINARY, value)), false))));
    Expression expression = toPredicate(result.getTupleDomain());
    assertEquals(expression, comparison(GREATER_THAN, new SymbolReference(C_VARBINARY), varbinaryLiteral(value)));
}
Also used : NotExpression(com.facebook.presto.sql.tree.NotExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 4 with ExtractionResult

use of com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult in project presto by prestodb.

the class TestExpressionDomainTranslator method testFromAndPredicate.

@Test
public void testFromAndPredicate() {
    Expression originalPredicate = and(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)));
    ExtractionResult result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), and(unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT)));
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, false, 5L, false)), false))));
    // Test complements
    assertUnsupportedPredicate(not(and(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)))));
    originalPredicate = not(and(not(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT))), not(and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)))));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), originalPredicate);
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
}
Also used : NotExpression(com.facebook.presto.sql.tree.NotExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 5 with ExtractionResult

use of com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult in project presto by prestodb.

the class TestExpressionDomainTranslator method assertUnsupportedPredicate.

private void assertUnsupportedPredicate(Expression expression) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), expression);
    assertEquals(result.getTupleDomain(), TupleDomain.all());
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult)

Aggregations

ExtractionResult (com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult)10 Test (org.testng.annotations.Test)6 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)3 Expression (com.facebook.presto.sql.tree.Expression)3 InListExpression (com.facebook.presto.sql.tree.InListExpression)3 NotExpression (com.facebook.presto.sql.tree.NotExpression)3 Domain (com.facebook.presto.common.predicate.Domain)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1