@Test
  public void testLikePredicateOnNullValues() throws Exception {
    Cache cache = CacheUtils.getCache();
    AttributesFactory attributesFactory = new AttributesFactory();
    RegionAttributes regionAttributes = attributesFactory.create();

    Region region = cache.createRegion("pos", regionAttributes);

    char ch = 'd';
    String base = "abc";
    for (int i = 1; i < 6; i++) {
      Portfolio pf = new Portfolio(i);
      pf.pkid = "abc";
      if (i % 2 == 0) {
        pf.pkid = null;
        pf.status = "like";
      } else if (i == 3) {
        pf.status = null;
      }
      region.put(i, pf);
    }

    QueryService qs = cache.getQueryService();
    Query q;
    SelectResults results;

    String[] query =
        new String[] {"SELECT distinct *  FROM " + SEPARATOR + "pos ps WHERE ps.pkid like '%b%'",
            "SELECT * FROM " + SEPARATOR
                + "pos ps WHERE ps.pkid like '%b%' and ps.status like '%ctiv%'",
            "SELECT * FROM " + SEPARATOR + "pos ps WHERE ps.pkid like '_bc'",
            "SELECT pkid FROM " + SEPARATOR + "pos ps WHERE ps.pkid like 'abc%'",
            "SELECT pkid FROM " + SEPARATOR + "pos ps WHERE ps.pkid = 'abc'",
            "SELECT pkid FROM " + SEPARATOR
                + "pos ps WHERE ps.pkid like '%b%' and ps.status = 'like'",
            "SELECT pkid FROM " + SEPARATOR
                + "pos ps WHERE ps.pkid like '%b%' and ps.status like '%ike'",
            "SELECT pkid FROM " + SEPARATOR
                + "pos ps WHERE ps.pkid like '%b%' and ps.pkid like '_bc'",
            "SELECT pkid FROM " + SEPARATOR
                + "pos ps WHERE ps.pkid like 'ml%' or ps.status = 'like'",};

    // null check
    for (final String value : query) {
      q = qs.newQuery(value);
      results = (SelectResults) q.execute(); // No NPE.
    }

    // validate results
    q = qs.newQuery(query[0]);
    results = (SelectResults) q.execute();
    assertEquals("Result size is not as expected", 3, results.size());

    q = qs.newQuery(query[1]);
    results = (SelectResults) q.execute();
    assertEquals("Result size is not as expected", 2, results.size());

    // Create index.
    qs.createIndex("pkid", IndexType.FUNCTIONAL, "ps.pkid", SEPARATOR + "pos ps");
    qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", SEPARATOR + "pos ps");

    for (final String s : query) {
      q = qs.newQuery(s);
      results = (SelectResults) q.execute(); // No NPE.
    }

    ResultsBag bag = new ResultsBag(null);
    for (int i = 1; i < 6; ++i) {
      bag.add(region.get(i));
    }
  }
Query with index on other fields.
geode-core/src/integrationTest/java/org/apache/geode/cache/query/functional/LikePredicateJUnitTest.java