Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.facebook.presto.sql.planner;
  
  
  import java.util.List;
  import java.util.Map;
  
  import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
  import static com.facebook.presto.spi.TupleDomain.withColumnDomains;
  import static com.facebook.presto.spi.type.BigintType.BIGINT;
  import static com.facebook.presto.spi.type.BooleanType.BOOLEAN;
  import static com.facebook.presto.spi.type.DateType.DATE;
  import static com.facebook.presto.spi.type.DoubleType.DOUBLE;
  import static com.facebook.presto.spi.type.TimestampType.TIMESTAMP;
  import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
  import static com.facebook.presto.sql.ExpressionUtils.and;
  import static com.facebook.presto.sql.ExpressionUtils.or;
  import static com.facebook.presto.sql.tree.BooleanLiteral.FALSE_LITERAL;
  import static com.facebook.presto.sql.tree.BooleanLiteral.TRUE_LITERAL;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.EQUAL;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.GREATER_THAN_OR_EQUAL;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.IS_DISTINCT_FROM;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.LESS_THAN;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.LESS_THAN_OR_EQUAL;
  import static com.facebook.presto.sql.tree.ComparisonExpression.Type.NOT_EQUAL;
  import static io.airlift.slice.Slices.utf8Slice;
  import static java.util.Collections.nCopies;
  import static org.testng.Assert.assertEquals;
  import static org.testng.Assert.assertTrue;
  
  public class TestDomainTranslator
  {
      private static final Metadata METADATA = MetadataManager.createTestMetadataManager();
  
      private static final Symbol A = new Symbol("a");
      private static final Symbol B = new Symbol("b");
      private static final Symbol C = new Symbol("c");
      private static final Symbol D = new Symbol("d");
      private static final Symbol E = new Symbol("e");
      private static final Symbol F = new Symbol("f");
      private static final Symbol G = new Symbol("g");
      private static final Symbol H = new Symbol("h");
      private static final Symbol I = new Symbol("i");
  
      private static final Map<SymbolTypeTYPES = ImmutableMap.<SymbolType>builder()
              .put()
              .put()
              .put()
              .put()
              .put()
              .put()
              .put()
              .put()
              .put()
              .build();
  
      private static final long TIMESTAMP_VALUE = new DateTime(2013, 3, 30, 1, 5, 0, 0, .).getMillis();
      private static final long DATE_VALUE = new DateTime(2001, 1, 22, 0, 0, 0, 0, .).getMillis();
 
     @Test
     public void testNoneRoundTrip()
             throws Exception
     {
         TupleDomain<SymboltupleDomain = TupleDomain.none();
         ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), tupleDomain);
     }
 
     @Test
     public void testAllRoundTrip()
             throws Exception
     {
         TupleDomain<SymboltupleDomain = TupleDomain.all();
         ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), tupleDomain);
     }
 
     @Test
     public void testRoundTrip()
             throws Exception
     {
         TupleDomain<SymboltupleDomain = withColumnDomains(ImmutableMap.<SymbolDomain>builder()
                 .put(, Domain.singleValue(1L))
                 .put(, Domain.onlyNull(Double.class))
                 .put(, Domain.notNull(Slice.class))
                 .put(, Domain.singleValue(true))
                 .put(, Domain.singleValue(2L))
                 .put(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(1.1), Range.equal(2.0), Range.range(3.0, false, 3.5, true)), true))
                 .put(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(utf8Slice("2013-01-01")), Range.greaterThan(utf8Slice("2013-10-01"))), false))
                 .put(, Domain.singleValue())
                 .put(, Domain.singleValue())
                 .build());
 
         ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), tupleDomain);
     }
 
     @Test
     public void testToPredicateNone()
             throws Exception
     {
         TupleDomain<SymboltupleDomain = withColumnDomains(ImmutableMap.<SymbolDomain>builder()
                 .put(, Domain.singleValue(1L))
                 .put(, Domain.onlyNull(Double.class))
                 .put(, Domain.notNull(Slice.class))
                 .put(, Domain.none(Boolean.class))
                 .build());
 
         assertEquals(toPredicate(tupleDomain), );
     }
 
     @Test
     public void testToPredicateAllIgnored()
             throws Exception
     {
         TupleDomain<SymboltupleDomain = withColumnDomains(ImmutableMap.<SymbolDomain>builder()
                 .put(, Domain.singleValue(1L))
                 .put(, Domain.onlyNull(Double.class))
                 .put(, Domain.notNull(Slice.class))
                 .put(, Domain.all(Boolean.class))
                 .build());
 
         ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<SymbolDomain>builder()
                 .put(, Domain.singleValue(1L))
                 .put(, Domain.onlyNull(Double.class))
                 .put(, Domain.notNull(Slice.class))
                 .build()));
     }
 
     @Test
     public void testToPredicate()
             throws Exception
     {
         TupleDomain<SymboltupleDomain;
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class)));
         assertEquals(toPredicate(tupleDomain), isNotNull());
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.onlyNull(Long.class)));
         assertEquals(toPredicate(tupleDomain), isNull());
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.none(Long.class)));
         assertEquals(toPredicate(tupleDomain), );
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.all(Long.class)));
         assertEquals(toPredicate(tupleDomain), );
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(1L)), false)));
         assertEquals(toPredicate(tupleDomain), greaterThan(longLiteral(1L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(1L)), false)));
         assertEquals(toPredicate(tupleDomain), greaterThanOrEqual(longLiteral(1L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(1L)), false)));
         assertEquals(toPredicate(tupleDomain), lessThan(longLiteral(1L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.range(0L, false, 1L, true)), false)));
         assertEquals(toPredicate(tupleDomain), and(greaterThan(longLiteral(0L)), lessThanOrEqual(longLiteral(1L))));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(1L)), false)));
         assertEquals(toPredicate(tupleDomain), lessThanOrEqual(longLiteral(1L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.singleValue(1L)));
         assertEquals(toPredicate(tupleDomain), equal(longLiteral(1L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(1L), Range.equal(2L)), false)));
         assertEquals(toPredicate(tupleDomain), in(, ImmutableList.of(1L, 2L)));
 
         tupleDomain = withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(1L)), true)));
         assertEquals(toPredicate(tupleDomain), or(lessThan(longLiteral(1L)), isNull()));
     }
 
     @Test
     public void testFromUnknownPredicate()
             throws Exception
     {
         assertTrue(result.getTupleDomain().isAll());
 
         // Test the complement
         result = fromPredicate(not(unprocessableExpression1()));
         assertTrue(result.getTupleDomain().isAll());
     }
 
     @Test
     public void testFromAndPredicate()
             throws Exception
     {
         Expression originalPredicate = and(
                 and(greaterThan(longLiteral(1L)), unprocessableExpression1()),
                 and(lessThan(longLiteral(5L)), unprocessableExpression2()));
         ExtractionResult result = fromPredicate(originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.range(1L, false, 5L, false)), false))));
 
         // Test complements
         originalPredicate = not(and(
                 and(greaterThan(longLiteral(1L)), unprocessableExpression1()),
                 and(lessThan(longLiteral(5L)), unprocessableExpression2())));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertTrue(result.getTupleDomain().isAll());
 
         originalPredicate = not(and(
                 not(and(greaterThan(longLiteral(1L)), unprocessableExpression1())),
                 not(and(lessThan(longLiteral(5L)), unprocessableExpression2()))));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class))));
     }
 
     @Test
     public void testFromOrPredicate()
             throws Exception
     {
         Expression originalPredicate = or(
                 and(greaterThan(longLiteral(1L)), unprocessableExpression1()),
                 and(lessThan(longLiteral(5L)), unprocessableExpression2()));
         ExtractionResult result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class))));
 
         originalPredicate = or(
                 and(equal(longLiteral(1L)), unprocessableExpression1()),
                 and(equal(longLiteral(2L)), unprocessableExpression2()));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(1L), Range.equal(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(longLiteral(1L)), unprocessableExpression1()),
                 and(equal(longLiteral(2L)), unprocessableExpression1()));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(1L), Range.equal(2L)), false))));
 
         // And not if they have different symbols
         originalPredicate = or(
                 and(equal(longLiteral(1L)), unprocessableExpression1()),
                 and(equal(doubleLiteral(2.0)), unprocessableExpression1()));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertTrue(result.getTupleDomain().isAll());
 
         // We can make another optimization if one side is the super set of the other side
         originalPredicate = or(
                 and(greaterThan(longLiteral(1L)), greaterThan(doubleLiteral(1.0)), unprocessableExpression1()),
                 and(greaterThan(longLiteral(2L)), greaterThan(doubleLiteral(2.0)), unprocessableExpression1()));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(
                 , Domain.create(SortedRangeSet.of(Range.greaterThan(1L)), false),
                 , Domain.create(SortedRangeSet.of(Range.greaterThan(1.0)), false))));
 
         // We can't make those inferences if the unprocessableExpressions are non-deterministic
         originalPredicate = or(
                 and(equal(longLiteral(1L)), randPredicate()),
                 and(equal(longLiteral(2L)), randPredicate()));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(1L), Range.equal(2L)), false))));
 
         // Test complements
         originalPredicate = not(or(
                 and(greaterThan(longLiteral(1L)), unprocessableExpression1()),
                 and(lessThan(longLiteral(5L)), unprocessableExpression2())));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), and(
                 not(and(greaterThan(longLiteral(1L)), unprocessableExpression1())),
                 not(and(lessThan(longLiteral(5L)), unprocessableExpression2()))));
         assertTrue(result.getTupleDomain().isAll());
 
         originalPredicate = not(or(
                 not(and(greaterThan(longLiteral(1L)), unprocessableExpression1())),
                 not(and(lessThan(longLiteral(5L)), unprocessableExpression2()))));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.range(1L, false, 5L, false)), false))));
     }
 
     @Test
     public void testFromNotPredicate()
             throws Exception
     {
         Expression originalPredicate = not(and(equal(longLiteral(1L)), unprocessableExpression1()));
         ExtractionResult result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertTrue(result.getTupleDomain().isAll());
 
         originalPredicate = not(unprocessableExpression1());
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), originalPredicate);
         assertTrue(result.getTupleDomain().isAll());
 
         originalPredicate = not();
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalPredicate = not(equal(longLiteral(1L)));
         result = fromPredicate(originalPredicate);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(1L), Range.greaterThan(1L)), false))));
     }
 
     @Test
     public void testFromUnprocessableComparison()
             throws Exception
     {
         // If it is not a simple comparison, we should not try to process it
         ExtractionResult result = fromPredicate(predicate);
         assertEquals(result.getRemainingExpression(), predicate);
         assertTrue(result.getTupleDomain().isAll());
 
         // Complement
         result = fromPredicate(predicate);
         assertEquals(result.getRemainingExpression(), predicate);
         assertTrue(result.getTupleDomain().isAll());
     }
 
     @Test
     public void testFromBasicComparisons()
             throws Exception
     {
         // Test out the extraction of all basic comparisons
         Expression originalExpression = greaterThan(longLiteral(2L));
         ExtractionResult result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
 
         originalExpression = greaterThanOrEqual(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
 
         originalExpression = lessThan(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
 
         originalExpression = lessThanOrEqual(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = equal(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
 
         originalExpression = notEqual(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
 
         originalExpression = isDistinctFrom(longLiteral(2L));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), true))));
 
         // Test complement
         originalExpression = not(greaterThan(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = not(greaterThanOrEqual(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
 
         originalExpression = not(lessThan(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
 
         originalExpression = not(lessThanOrEqual(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
 
         originalExpression = not(equal(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
 
         originalExpression = not(notEqual(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
 
         originalExpression = not(isDistinctFrom(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
     }
 
     @Test
     public void testFromFlippedBasicComparisons()
             throws Exception
     {
         // Test out the extraction of all basic comparisons where the reference literal ordering is flipped
         ComparisonExpression originalExpression = comparison(longLiteral(2L), reference());
         ExtractionResult result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
 
         originalExpression = comparison(longLiteral(2L), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), true))));
 
         originalExpression = comparison(nullLiteral(), reference());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class))));
     }
 
     @Test
     public void testFromBasicComparisonsWithNulls()
             throws Exception
     {
         // Test out the extraction of all basic comparisons with null literals
         Expression originalExpression = greaterThan(nullLiteral());
         ExtractionResult result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = greaterThanOrEqual(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = lessThan(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = lessThanOrEqual(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = equal(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = notEqual(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = isDistinctFrom(nullLiteral());
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class))));
 
         // Test complements
         originalExpression = not(greaterThan(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(greaterThanOrEqual(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(lessThan(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(lessThanOrEqual(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(equal(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(notEqual(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isNone());
 
         originalExpression = not(isDistinctFrom(nullLiteral()));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.onlyNull(Long.class))));
     }
 
     @Test
             throws Exception
     {
         // B is a double column. Check that it can be compared against longs
         Expression originalExpression = greaterThan(longLiteral(2L));
         ExtractionResult result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2.0)), false))));
 
         // C is a string column. Check that it can be compared.
         originalExpression = greaterThan(stringLiteral("test"));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(utf8Slice("test"))), false))));
 
         // A is a long column. Check that it can be compared against doubles
         originalExpression = greaterThan(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
 
         originalExpression = greaterThan(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThan(2L)), false))));
 
         originalExpression = greaterThanOrEqual(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(2L)), false))));
 
         originalExpression = greaterThanOrEqual(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.greaterThanOrEqual(3L)), false))));
 
         originalExpression = lessThan(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
 
         originalExpression = lessThan(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(3L)), false))));
 
         originalExpression = lessThanOrEqual(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = lessThanOrEqual(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = equal(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.equal(2L)), false))));
 
         originalExpression = equal(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.none(Long.class))));
 
         originalExpression = notEqual(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), false))));
 
         originalExpression = notEqual(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.notNull(Long.class))));
 
         originalExpression = isDistinctFrom(doubleLiteral(2.0));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L), Range.greaterThan(2L)), true))));
 
         originalExpression = isDistinctFrom(doubleLiteral(2.1));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertTrue(result.getTupleDomain().isAll());
 
         // Test complements
 
         // B is a double column. Check that it can be compared against longs
         originalExpression = not(greaterThan(longLiteral(2L)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2.0)), false))));
 
         // C is a string column. Check that it can be compared.
         originalExpression = not(greaterThan(stringLiteral("test")));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, 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(doubleLiteral(2.0)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = not(greaterThan(doubleLiteral(2.1)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThanOrEqual(2L)), false))));
 
         originalExpression = not(greaterThanOrEqual(doubleLiteral(2.0)));
         result = fromPredicate(originalExpression);
         assertEquals(result.getRemainingExpression(), );
         assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(, Domain.create(SortedRangeSet.of(Range.lessThan(2L)), false))));
 
         originalExpression = not(greaterThanOrEqual(