public void testFromBasicComparisons()
throws Exception
{
// Test out the extraction of all basic comparisons
Expression originalExpression = greaterThan(A, longLiteral(2L));
ExtractionResult result = fromPredicate(MANAGER, TEST_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, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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 = lessThan(A, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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 = lessThanOrEqual(A, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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 = notEqual(A, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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 = isDistinctFrom(A, longLiteral(2L));
result = fromPredicate(MANAGER, TEST_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))));
// Test complement
originalExpression = not(greaterThan(A, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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(lessThan(A, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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(lessThanOrEqual(A, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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(notEqual(A, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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, longLiteral(2L)));
result = fromPredicate(MANAGER, TEST_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))));
}