assertPredicateIsAlwaysFalse(not(greaterThan(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(greaterThanOrEqual(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(lessThan(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(lessThanOrEqual(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(equal(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(equal(C_COLOR, nullLiteral(COLOR)))); assertPredicateIsAlwaysFalse(not(notEqual(C_BIGINT, nullLiteral(BIGINT)))); assertPredicateIsAlwaysFalse(not(notEqual(C_COLOR, nullLiteral(COLOR)))); not(isDistinctFrom(C_BIGINT, nullLiteral(BIGINT))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT)))); not(isDistinctFrom(C_COLOR, nullLiteral(COLOR))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.onlyNull(COLOR))));
@Test public void testFromUnknownPredicate() { assertUnsupportedPredicate(unprocessableExpression1(C_BIGINT)); assertUnsupportedPredicate(not(unprocessableExpression1(C_BIGINT))); }
not(greaterThan(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(BIGINT, 2L)), false)))); not(greaterThanOrEqual(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 2L)), false)))); not(lessThan(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThanOrEqual(BIGINT, 2L)), false)))); not(lessThanOrEqual(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(BIGINT, 2L)), false)))); not(equal(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 2L), Range.greaterThan(BIGINT, 2L)), false)))); not(notEqual(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 2L)), false)))); not(isDistinctFrom(C_BIGINT, bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 2L)), false)))); not(equal(C_COLOR, colorLiteral(COLOR_VALUE_1))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1).complement(), false)))); not(in(C_COLOR, ImmutableList.of(colorLiteral(COLOR_VALUE_1), colorLiteral(COLOR_VALUE_2)))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1, COLOR_VALUE_2).complement(), false)))); not(isDistinctFrom(C_COLOR, colorLiteral(COLOR_VALUE_1))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1), false))));
@Test public void testFromNullLiteralPredicate() { assertPredicateIsAlwaysFalse(nullLiteral()); assertPredicateIsAlwaysFalse(not(nullLiteral())); }
not(greaterThan(C_DOUBLE, cast(bigintLiteral(2L), DOUBLE))), withColumnDomains(ImmutableMap.of(C_DOUBLE, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(DOUBLE, 2.0)), false)))); not(greaterThan(C_VARCHAR, stringLiteral("test", VARCHAR))), withColumnDomains(ImmutableMap.of(C_VARCHAR, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(VARCHAR, utf8Slice("test"))), false)))); not(greaterThan(cast(C_INTEGER, DOUBLE), doubleLiteral(2.0))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(INTEGER, 2L)), false)))); not(greaterThan(cast(C_INTEGER, DOUBLE), doubleLiteral(2.1))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(INTEGER, 2L)), false)))); not(greaterThanOrEqual(cast(C_INTEGER, DOUBLE), doubleLiteral(2.0))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.lessThan(INTEGER, 2L)), false)))); not(greaterThanOrEqual(cast(C_INTEGER, DOUBLE), doubleLiteral(2.1))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(INTEGER, 2L)), false)))); not(lessThan(cast(C_INTEGER, DOUBLE), doubleLiteral(2.0))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.greaterThanOrEqual(INTEGER, 2L)), false)))); not(lessThan(cast(C_INTEGER, DOUBLE), doubleLiteral(2.1))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.greaterThan(INTEGER, 2L)), false)))); not(lessThanOrEqual(cast(C_INTEGER, DOUBLE), doubleLiteral(2.0))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.greaterThan(INTEGER, 2L)), false)))); not(lessThanOrEqual(cast(C_INTEGER, DOUBLE), doubleLiteral(2.1))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.greaterThan(INTEGER, 2L)), false))));
@Test public void testFromNotPredicate() { assertUnsupportedPredicate(not(and(equal(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)))); assertUnsupportedPredicate(not(unprocessableExpression1(C_BIGINT))); assertPredicateIsAlwaysFalse(not(TRUE_LITERAL)); assertPredicateTranslates( not(equal(C_BIGINT, bigintLiteral(1L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 1L)), false)))); }
@Test public void testInPredicateWithNull() { assertPredicateTranslates( in(C_BIGINT, Arrays.asList(1L, 2L, null)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false)))); assertPredicateIsAlwaysFalse(not(in(C_BIGINT, Arrays.asList(1L, 2L, null)))); assertPredicateIsAlwaysFalse(in(C_BIGINT, Arrays.asList(new Long[] {null}))); assertPredicateIsAlwaysFalse(not(in(C_BIGINT, Arrays.asList(new Long[] {null})))); assertUnsupportedPredicate(isNull(in(C_BIGINT, Arrays.asList(1L, 2L, null)))); assertUnsupportedPredicate(isNotNull(in(C_BIGINT, Arrays.asList(1L, 2L, null)))); assertUnsupportedPredicate(isNull(in(C_BIGINT, Arrays.asList(new Long[] {null})))); assertUnsupportedPredicate(isNotNull(in(C_BIGINT, Arrays.asList(new Long[] {null})))); }
@Test public void testFromIsNullPredicate() { assertPredicateTranslates( isNull(C_BIGINT), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT)))); assertPredicateTranslates( isNull(C_HYPER_LOG_LOG), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.onlyNull(HYPER_LOG_LOG)))); assertPredicateTranslates( not(isNull(C_BIGINT)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT)))); assertPredicateTranslates( not(isNull(C_HYPER_LOG_LOG)), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.notNull(HYPER_LOG_LOG)))); }
@Test public void testFromIsNotNullPredicate() { assertPredicateTranslates( isNotNull(C_BIGINT), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT)))); assertPredicateTranslates( isNotNull(C_HYPER_LOG_LOG), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.notNull(HYPER_LOG_LOG)))); assertPredicateTranslates( not(isNotNull(C_BIGINT)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT)))); assertPredicateTranslates( not(isNotNull(C_HYPER_LOG_LOG)), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.onlyNull(HYPER_LOG_LOG)))); }
@Test public void testFromUnprocessableComparison() { assertUnsupportedPredicate(comparison(GREATER_THAN, unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT))); assertUnsupportedPredicate(not(comparison(GREATER_THAN, unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT)))); }
@Test public void testFromInPredicate() { assertPredicateTranslates( in(C_BIGINT, ImmutableList.of(1L)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.singleValue(BIGINT, 1L)))); assertPredicateTranslates( in(C_COLOR, ImmutableList.of(colorLiteral(COLOR_VALUE_1))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.singleValue(COLOR, COLOR_VALUE_1)))); assertPredicateTranslates( in(C_BIGINT, ImmutableList.of(1L, 2L)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false)))); assertPredicateTranslates( in(C_COLOR, ImmutableList.of(colorLiteral(COLOR_VALUE_1), colorLiteral(COLOR_VALUE_2))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1, COLOR_VALUE_2), false)))); assertPredicateTranslates( not(in(C_BIGINT, ImmutableList.of(1L, 2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.range(BIGINT, 1L, false, 2L, false), Range.greaterThan(BIGINT, 2L)), false)))); assertPredicateTranslates( not(in(C_COLOR, ImmutableList.of(colorLiteral(COLOR_VALUE_1), colorLiteral(COLOR_VALUE_2)))), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1, COLOR_VALUE_2).complement(), false)))); }
@Test public void testFromUnprocessableInPredicate() { assertUnsupportedPredicate(new InPredicate(unprocessableExpression1(C_BIGINT), new InListExpression(ImmutableList.of(TRUE_LITERAL)))); assertUnsupportedPredicate(new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN))))); assertUnsupportedPredicate( new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(TRUE_LITERAL, unprocessableExpression1(C_BOOLEAN))))); assertUnsupportedPredicate(not(new InPredicate(C_BOOLEAN.toSymbolReference(), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN)))))); }
@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)))); }
@Test public void testFromInPredicateWithCastsAndNulls() { assertPredicateIsAlwaysFalse(new InPredicate( C_BIGINT.toSymbolReference(), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT))))); assertUnsupportedPredicate(not(new InPredicate( cast(C_SMALLINT, BIGINT), new InListExpression(ImmutableList.of(toExpression(null, BIGINT)))))); assertPredicateTranslates( new InPredicate( C_BIGINT.toSymbolReference(), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT), toExpression(1L, BIGINT)))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), false)))); assertPredicateIsAlwaysFalse(not(new InPredicate( C_BIGINT.toSymbolReference(), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT), toExpression(1L, SMALLINT)))))); }
assertEquals(toPredicate(tupleDomain), or(not(equal(C_COLOR, colorLiteral(COLOR_VALUE_1))), isNull(C_COLOR)));
@Test public void testFromBetweenPredicate() { assertPredicateTranslates( between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L)), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 2L, true)), false)))); assertPredicateTranslates( between(cast(C_INTEGER, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1)), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.range(INTEGER, 1L, true, 2L, true)), false)))); assertPredicateIsAlwaysFalse(between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT))); // Test complements assertPredicateTranslates( not(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 2L)), false)))); assertPredicateTranslates( not(between(cast(C_INTEGER, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1))), withColumnDomains(ImmutableMap.of(C_INTEGER, Domain.create(ValueSet.ofRanges(Range.lessThan(INTEGER, 1L), Range.greaterThan(INTEGER, 2L)), false)))); assertPredicateTranslates( not(between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L)), false)))); }
assertEquals(toPredicate(tupleDomain), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))); assertEquals(toPredicate(tupleDomain), and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L))))); assertEquals(toPredicate(tupleDomain), or(and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), between(C_BIGINT, bigintLiteral(7L), bigintLiteral(9L)))); and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThan(C_BIGINT, bigintLiteral(9L))), and(greaterThan(C_BIGINT, bigintLiteral(11L)), lessThan(C_BIGINT, bigintLiteral(13L)))));
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)));
@Test public void testFromNullLiteralPredicate() throws Exception { Expression originalExpression = nullLiteral(); ExtractionResult result = fromPredicate(originalExpression); assertEquals(result.getRemainingExpression(), TRUE_LITERAL); assertTrue(result.getTupleDomain().isNone()); originalExpression = not(nullLiteral()); result = fromPredicate(originalExpression); assertEquals(result.getRemainingExpression(), TRUE_LITERAL); assertTrue(result.getTupleDomain().isNone()); }