Search in sources :

Example 6 with ExtractionResult

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

the class TestExpressionDomainTranslator method testFromOrPredicate.

@Test
public void testFromOrPredicate() {
    Expression originalPredicate = or(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(), originalPredicate);
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
    originalPredicate = or(and(equal(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(equal(C_BIGINT, bigintLiteral(2L)), unprocessableExpression2(C_BIGINT)));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), originalPredicate);
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false))));
    // Same unprocessableExpression means that we can do more extraction
    // If both sides are operating on the same single symbol
    originalPredicate = or(and(equal(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(equal(C_BIGINT, bigintLiteral(2L)), unprocessableExpression1(C_BIGINT)));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), unprocessableExpression1(C_BIGINT));
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false))));
    // And not if they have different symbols
    assertUnsupportedPredicate(or(and(equal(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(equal(C_DOUBLE, doubleLiteral(2.0)), unprocessableExpression1(C_BIGINT))));
    // We can make another optimization if one side is the super set of the other side
    originalPredicate = or(and(greaterThan(C_BIGINT, bigintLiteral(1L)), greaterThan(C_DOUBLE, doubleLiteral(1.0)), unprocessableExpression1(C_BIGINT)), and(greaterThan(C_BIGINT, bigintLiteral(2L)), greaterThan(C_DOUBLE, doubleLiteral(2.0)), unprocessableExpression1(C_BIGINT)));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), unprocessableExpression1(C_BIGINT));
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(BIGINT, 1L)), false), C_DOUBLE, Domain.create(ValueSet.ofRanges(Range.greaterThan(DOUBLE, 1.0)), false))));
    // We can't make those inferences if the unprocessableExpressions are non-deterministic
    originalPredicate = or(and(equal(C_BIGINT, bigintLiteral(1L)), randPredicate(C_BIGINT, BIGINT)), and(equal(C_BIGINT, bigintLiteral(2L)), randPredicate(C_BIGINT, BIGINT)));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), originalPredicate);
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false))));
    // Test complements
    originalPredicate = not(or(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT))));
    result = fromPredicate(originalPredicate);
    assertEquals(result.getRemainingExpression(), and(not(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT))), not(and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)))));
    assertTrue(result.getTupleDomain().isAll());
    originalPredicate = not(or(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(), 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))));
}
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 7 with ExtractionResult

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

the class TestExpressionDomainTranslator method testToPredicateAllIgnored.

@Test
public void testToPredicateAllIgnored() {
    TupleDomain<String> tupleDomain = withColumnDomains(ImmutableMap.<String, 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.all(BOOLEAN)).build());
    ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<String, Domain>builder().put(C_BIGINT, Domain.singleValue(BIGINT, 1L)).put(C_DOUBLE, Domain.onlyNull(DOUBLE)).put(C_VARCHAR, Domain.notNull(VARCHAR)).build()));
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Test(org.testng.annotations.Test)

Example 8 with ExtractionResult

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

the class TestExpressionDomainTranslator method testSimpleComparison.

private void testSimpleComparison(Expression expression, String symbol, Domain domain) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    TupleDomain<String> actual = result.getTupleDomain();
    TupleDomain<String> 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.getSqlFunctionProperties()), actual.toString(SESSION.getSqlFunctionProperties())));
    }
}
Also used : ExtractionResult(com.facebook.presto.sql.planner.ExpressionDomainTranslator.ExtractionResult)

Example 9 with ExtractionResult

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

the class TestExpressionDomainTranslator method testNoneRoundTrip.

@Test
public void testNoneRoundTrip() {
    TupleDomain<String> tupleDomain = TupleDomain.none();
    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 10 with ExtractionResult

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

the class TestExpressionDomainTranslator method assertPredicateTranslates.

private void assertPredicateTranslates(Expression expression, TupleDomain<String> tupleDomain) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertEquals(result.getTupleDomain(), tupleDomain);
}
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