private static ComparisonExpression lessThan(Expression left, Expression expression) { return comparison(LESS_THAN, left, expression); }
private static ComparisonExpression isDistinctFrom(Expression left, Expression right) { return comparison(IS_DISTINCT_FROM, left, right); }
private static ComparisonExpression notEqual(Expression left, Expression right) { return comparison(NOT_EQUAL, left, right); }
private static ComparisonExpression greaterThan(Expression left, Expression right) { return comparison(GREATER_THAN, left, right); }
private static ComparisonExpression lessThanOrEqual(Expression left, Expression right) { return comparison(LESS_THAN_OR_EQUAL, left, right); }
private static ComparisonExpression equal(Expression left, Expression right) { return comparison(EQUAL, left, right); }
private static ComparisonExpression greaterThanOrEqual(Expression left, Expression right) { return comparison(GREATER_THAN_OR_EQUAL, left, right); }
private static Expression unprocessableExpression2(Symbol symbol) { return comparison(LESS_THAN, symbol.toSymbolReference(), symbol.toSymbolReference()); }
private static Expression unprocessableExpression1(Symbol symbol) { return comparison(GREATER_THAN, symbol.toSymbolReference(), symbol.toSymbolReference()); }
@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 testExpressionConstantFolding() { Expression originalExpression = comparison(GREATER_THAN, C_VARBINARY.toSymbolReference(), 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, C_VARBINARY.toSymbolReference(), varbinaryLiteral(value))); }
private static Expression randPredicate(Symbol symbol, Type type) { return comparison(GREATER_THAN, symbol.toSymbolReference(), cast(new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), type)); }
@Test void testMultipleCoercionsOnSymbolSide() { assertPredicateTranslates( comparison(GREATER_THAN, cast(cast(C_SMALLINT, REAL), DOUBLE), doubleLiteral(3.7)), withColumnDomains(ImmutableMap.of(C_SMALLINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(SMALLINT, 3L)), false)))); }
@Test public void testConjunctExpression() { Expression expression = and( comparison(GREATER_THAN, C_DOUBLE.toSymbolReference(), doubleLiteral(0)), comparison(GREATER_THAN, C_BIGINT.toSymbolReference(), bigintLiteral(0))); assertPredicateTranslates( expression, withColumnDomains(ImmutableMap.of( C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(BIGINT, 0L)), false), C_DOUBLE, Domain.create(ValueSet.ofRanges(Range.greaterThan(DOUBLE, .0)), false)))); assertEquals( toPredicate(fromPredicate(expression).getTupleDomain()), and( comparison(GREATER_THAN, C_BIGINT.toSymbolReference(), bigintLiteral(0)), comparison(GREATER_THAN, C_DOUBLE.toSymbolReference(), doubleLiteral(0)))); }
comparison(GREATER_THAN, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 2L)), false)))); comparison(GREATER_THAN_OR_EQUAL, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(BIGINT, 2L)), false)))); comparison(LESS_THAN, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(BIGINT, 2L)), false)))); comparison(LESS_THAN_OR_EQUAL, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThanOrEqual(BIGINT, 2L)), false)))); assertPredicateTranslates(comparison(EQUAL, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 2L)), false)))); assertPredicateTranslates(comparison(EQUAL, colorLiteral(COLOR_VALUE_1), C_COLOR.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1), false)))); assertPredicateTranslates(comparison(NOT_EQUAL, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 2L), Range.greaterThan(BIGINT, 2L)), false)))); comparison(NOT_EQUAL, colorLiteral(COLOR_VALUE_1), C_COLOR.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1).complement(), false)))); assertPredicateTranslates(comparison(IS_DISTINCT_FROM, bigintLiteral(2L), C_BIGINT.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 2L), Range.greaterThan(BIGINT, 2L)), true)))); comparison(IS_DISTINCT_FROM, colorLiteral(COLOR_VALUE_1), C_COLOR.toSymbolReference()), withColumnDomains(ImmutableMap.of(C_COLOR, Domain.create(ValueSet.of(COLOR, COLOR_VALUE_1).complement(), true))));
private static ComparisonExpression lessThan(Symbol symbol, Expression expression) { return comparison(LESS_THAN, reference(symbol), expression); }
private static ComparisonExpression isDistinctFrom(Symbol symbol, Expression expression) { return comparison(IS_DISTINCT_FROM, reference(symbol), expression); }
private static Expression unprocessableExpression1(Symbol symbol) { return comparison(GREATER_THAN, reference(symbol), reference(symbol)); }
private static Expression randPredicate(Symbol symbol) { return comparison(GREATER_THAN, reference(symbol), new FunctionCall(new QualifiedName("rand"), ImmutableList.<Expression>of())); }
@Test public void testExpressionConstantFolding() throws Exception { Expression originalExpression = comparison(GREATER_THAN, reference(L), 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(L, Domain.create(ValueSet.ofRanges(Range.greaterThan(VARBINARY, value)), false)))); Expression expression = toPredicate(result.getTupleDomain()); assertEquals(expression, comparison(GREATER_THAN, reference(L), varbinaryLiteral(value))); }