You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2016/09/12 21:41:26 UTC

incubator-geode git commit: GEODE-1881: Support null map keys in CompactMapRangeIndex

Repository: incubator-geode
Updated Branches:
  refs/heads/develop 71c863b5c -> 4f2a51acc


GEODE-1881: Support null map keys in CompactMapRangeIndex

Allow indexing maps with null keys by storing the keys as
IndexManager.NULL.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/4f2a51ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4f2a51ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4f2a51ac

Branch: refs/heads/develop
Commit: 4f2a51acc660f1d49400c8d90471e10e91b09fb8
Parents: 71c863b
Author: Dan Smith <up...@apache.org>
Authored: Fri Sep 9 15:37:00 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Sep 12 14:35:26 2016 -0700

----------------------------------------------------------------------
 .../internal/index/CompactMapRangeIndex.java    | 11 +++++
 .../index/CompactRangeIndexJUnitTest.java       | 48 +++++++++++++++++++-
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4f2a51ac/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/CompactMapRangeIndex.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/CompactMapRangeIndex.java b/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/CompactMapRangeIndex.java
index c374a10..a089853 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/CompactMapRangeIndex.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/CompactMapRangeIndex.java
@@ -125,6 +125,13 @@ public class CompactMapRangeIndex extends AbstractMapIndex
   protected void doIndexAddition(Object mapKey, Object indexKey, Object value,
       RegionEntry entry) throws IMQException
   {
+    if (indexKey == null) {
+      indexKey = IndexManager.NULL;
+    }
+    if(mapKey == null) {
+      mapKey = IndexManager.NULL;
+    }
+
     boolean isPr = this.region instanceof BucketRegion;
     // Get RangeIndex for it or create it if absent
     CompactRangeIndex rg = (CompactRangeIndex)this.mapKeyToValueIndex.get(mapKey);
@@ -168,6 +175,10 @@ public class CompactMapRangeIndex extends AbstractMapIndex
     if (indexKey == null) {
       indexKey = IndexManager.NULL;
     }
+    if(mapKey == null) {
+      mapKey = IndexManager.NULL;
+    }
+
     boolean isPr = this.region instanceof BucketRegion;
     // Get RangeIndex for it or create it if absent
     CompactRangeIndex rg = (CompactRangeIndex) this.mapKeyToValueIndex.get(mapKey);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4f2a51ac/geode-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/CompactRangeIndexJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/CompactRangeIndexJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/CompactRangeIndexJUnitTest.java
index f01f925..67fa553 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/CompactRangeIndexJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/CompactRangeIndexJUnitTest.java
@@ -86,7 +86,7 @@ public class CompactRangeIndexJUnitTest  {
   public void testNullKeyCompactRangeIndex() throws Exception {
     index = utils.createIndex("indexName", "status", "/exampleRegion");
     Region region = utils.getCache().getRegion("exampleRegion");
-   
+
     //create objects
     int numObjects = 10;
     for (int i = 1; i <= numObjects; i++) {
@@ -101,6 +101,52 @@ public class CompactRangeIndexJUnitTest  {
   }
 
   /**
+   * Tests adding entries to compact range index where the the key
+   * of an indexed map field is null.
+   */
+  @Test
+  public void testNullMapKeyCompactRangeIndex() throws Exception {
+    index = utils.createIndex("indexName", "positions[*]", "/exampleRegion");
+    Region region = utils.getCache().getRegion("exampleRegion");
+
+    //create objects
+    int numObjects = 10;
+    for (int i = 1; i <= numObjects; i++) {
+      Portfolio p = new Portfolio(i);
+      p.status = null;
+      p.getPositions().put(null, "something");
+      region.put("KEY-"+ i, p);
+    }
+    //execute query and check result size
+    QueryService qs = utils.getCache().getQueryService();
+    SelectResults results = (SelectResults) qs.newQuery("Select * from /exampleRegion r where r.position[null] = something").execute();
+    assertEquals("Null matched Results expected", numObjects, results.size());
+  }
+
+  /**
+   * Tests adding entries to compact range index where the the key
+   * of an indexed map field is null.
+   */
+  @Test
+  public void testNullMapKeyCompactRangeIndexCreateIndexLater() throws Exception {
+    Region region = utils.getCache().getRegion("exampleRegion");
+
+    //create objects
+    int numObjects = 10;
+    for (int i = 1; i <= numObjects; i++) {
+      Portfolio p = new Portfolio(i);
+      p.status = null;
+      p.getPositions().put(null, "something");
+      region.put("KEY-"+ i, p);
+    }
+    index = utils.createIndex("indexName", "positions[*]", "/exampleRegion");
+    //execute query and check result size
+    QueryService qs = utils.getCache().getQueryService();
+    SelectResults results = (SelectResults) qs.newQuery("Select * from /exampleRegion r where r.position[null] = something").execute();
+    assertEquals("Null matched Results expected", numObjects, results.size());
+  }
+
+  /**
    * Tests race condition where we possibly were missing remove calls due to transitioning
    * to an empty index elem before adding the entries
    * the fix is to add the entries to the elem and then transition to that elem