Search in sources :

Example 21 with ExtractionResult

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());
}
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 22 with ExtractionResult

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))));
}
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 23 with ExtractionResult

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);
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 24 with ExtractionResult

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))));
}
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)

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