public void testFromComparisonsWithImplictCoercions()
throws Exception
{
// B is a double column. Check that it can be compared against longs
Expression originalExpression = greaterThan(B, longLiteral(2L));
ExtractionResult result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(BCH, Domain.create(SortedRangeSet.of(Range.greaterThan(2.0)), false))));
// C is a string column. Check that it can be compared.
originalExpression = greaterThan(C, stringLiteral("test"));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(CCH, Domain.create(SortedRangeSet.of(Range.greaterThan(utf8Slice("test"))), false))));
// A is a long column. Check that it can be compared against doubles
originalExpression = greaterThan(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
originalExpression = greaterThan(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
originalExpression = greaterThanOrEqual(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
originalExpression = greaterThanOrEqual(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(3L)), false))));
originalExpression = lessThan(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
originalExpression = lessThan(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(3L)), false))));
originalExpression = lessThanOrEqual(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
originalExpression = lessThanOrEqual(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
originalExpression = equal(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
originalExpression = equal(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.none(Long.class))));
originalExpression = notEqual(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
originalExpression = notEqual(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.notNull(Long.class))));
originalExpression = isDistinctFrom(A, doubleLiteral(2.0));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), true))));
originalExpression = isDistinctFrom(A, doubleLiteral(2.1));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertTrue(result.getTupleDomain().isAll());
// Test complements
// B is a double column. Check that it can be compared against longs
originalExpression = not(greaterThan(B, longLiteral(2L)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(BCH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2.0)), false))));
// C is a string column. Check that it can be compared.
originalExpression = not(greaterThan(C, stringLiteral("test")));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(CCH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(utf8Slice("test"))), false))));
// A is a long column. Check that it can be compared against doubles
originalExpression = not(greaterThan(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
originalExpression = not(greaterThan(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
originalExpression = not(greaterThanOrEqual(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
originalExpression = not(greaterThanOrEqual(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(3L)), false))));
originalExpression = not(lessThan(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
originalExpression = not(lessThan(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(3L)), false))));
originalExpression = not(lessThanOrEqual(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
originalExpression = not(lessThanOrEqual(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
originalExpression = not(equal(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
originalExpression = not(equal(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.notNull(Long.class))));
originalExpression = not(notEqual(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
originalExpression = not(notEqual(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.none(Long.class))));
originalExpression = not(isDistinctFrom(A, doubleLiteral(2.0)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<ColumnHandle, Domain>of(ACH, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
originalExpression = not(isDistinctFrom(A, doubleLiteral(2.1)));
result = fromPredicate(MANAGER, SESSION, originalExpression, TYPES, COLUMN_HANDLES);
Assert.assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
Assert.assertTrue(result.getTupleDomain().isNone());
}