Search in sources :

Example 6 with ExtractionResult

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

the class TestDomainTranslator method testSimpleComparison.

private static void testSimpleComparison(Expression expression, Symbol symbol, Domain domain) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    TupleDomain<Symbol> actual = result.getTupleDomain();
    TupleDomain<Symbol> expected = withColumnDomains(ImmutableMap.of(symbol, domain));
    if (!actual.equals(expected)) {
        fail(format("for comparison [%s] expected %s but found %s", expression.toString(), expected.toString(SESSION), actual.toString(SESSION)));
    }
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult)

Example 7 with ExtractionResult

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

the class TestDomainTranslator method testAllRoundTrip.

@Test
public void testAllRoundTrip() throws Exception {
    TupleDomain<Symbol> 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.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 8 with ExtractionResult

use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult 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());
}
Also used : NotExpression(com.facebook.presto.sql.tree.NotExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) LiteralInterpreter.toExpression(com.facebook.presto.sql.planner.LiteralInterpreter.toExpression) Expression(com.facebook.presto.sql.tree.Expression) ExtractionResult(com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 9 with ExtractionResult

use of com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult 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))));
}
Also used : NotExpression(com.facebook.presto.sql.tree.NotExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) LiteralInterpreter.toExpression(com.facebook.presto.sql.planner.LiteralInterpreter.toExpression) Expression(com.facebook.presto.sql.tree.Expression) ExtractionResult(com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 10 with ExtractionResult

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

the class TestDomainTranslator method testFromUnknownPredicate.

@Test
public void testFromUnknownPredicate() throws Exception {
    ExtractionResult result = fromPredicate(unprocessableExpression1(C_BIGINT));
    assertTrue(result.getTupleDomain().isAll());
    assertEquals(result.getRemainingExpression(), unprocessableExpression1(C_BIGINT));
    // Test the complement
    result = fromPredicate(not(unprocessableExpression1(C_BIGINT)));
    assertTrue(result.getTupleDomain().isAll());
    assertEquals(result.getRemainingExpression(), not(unprocessableExpression1(C_BIGINT)));
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Aggregations

ExtractionResult (com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult)24 Test (org.testng.annotations.Test)23 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)18 LiteralInterpreter.toExpression (com.facebook.presto.sql.planner.LiteralInterpreter.toExpression)16 Expression (com.facebook.presto.sql.tree.Expression)16 InListExpression (com.facebook.presto.sql.tree.InListExpression)16 NotExpression (com.facebook.presto.sql.tree.NotExpression)16 Domain (com.facebook.presto.spi.predicate.Domain)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 Cast (com.facebook.presto.sql.tree.Cast)1 InPredicate (com.facebook.presto.sql.tree.InPredicate)1 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1