geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject incubator-geode git commit: GEODE-1453: when parsing field value, should consider it is null
Date Wed, 25 May 2016 00:27:09 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop bd892f531 -> 31096fbf9


GEODE-1453: when parsing field value, should consider it is 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/31096fbf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/31096fbf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/31096fbf

Branch: refs/heads/develop
Commit: 31096fbf927e75ba30c25deea985c2b40af75f75
Parents: bd892f5
Author: zhouxh <gzhou@pivotal.io>
Authored: Tue May 24 17:25:37 2016 -0700
Committer: zhouxh <gzhou@pivotal.io>
Committed: Tue May 24 17:26:34 2016 -0700

----------------------------------------------------------------------
 .../serializer/PdxLuceneSerializer.java         |  3 +++
 .../serializer/ReflectionLuceneSerializer.java  |  3 +++
 .../lucene/LuceneQueriesIntegrationTest.java    | 20 +++++++++++++++++++-
 .../serializer/PdxFieldMapperJUnitTest.java     | 20 ++++++++++++++++++++
 .../ReflectionFieldMapperJUnitTest.java         | 16 ++++++++++++++++
 5 files changed, 61 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/31096fbf/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
index 3990614..13465d7 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
@@ -44,6 +44,9 @@ class PdxLuceneSerializer implements LuceneSerializer {
     for(String field : indexedFields) {
       if(pdx.hasField(field)) {
         Object fieldValue = pdx.getField(field);
+        if (fieldValue == null) {
+          continue;
+        }
         SerializerUtil.addField(doc, field, fieldValue);
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/31096fbf/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
index a76478c..e06f99e 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
@@ -70,6 +70,9 @@ class ReflectionLuceneSerializer implements LuceneSerializer {
     for(Field field: fields) {
       try {
         Object fieldValue = field.get(value);
+        if (fieldValue == null) {
+          continue;
+        }
         SerializerUtil.addField(doc, field.getName(), fieldValue);
       } catch (IllegalArgumentException | IllegalAccessException e) {
         //TODO - what to do if we can't read a field?

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/31096fbf/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 4ebb9c4..13df7a9 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -134,7 +134,25 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest
{
     verifyQuery("field1:one AND field2:two", "A");
     verifyQuery("field1:three AND field2:four", "A");
   }
-  
+
+  @Test()
+  public void shouldAllowNullInFieldValue() throws ParseException {
+    Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
+    fields.put("field1", null);
+    fields.put("field2", null);
+    luceneService.createIndex(INDEX_NAME, REGION_NAME, fields);
+    Region region = cache.createRegionFactory(RegionShortcut.PARTITION)
+      .create(REGION_NAME);
+    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+
+    //Put two values with some of the same tokens
+    String value1 = "one three";
+    region.put("A", new TestObject(value1, null));
+    index.waitUntilFlushed(60000);
+
+    verifyQuery("field1:one", "A");
+  }
+
   @Test()
   public void throwFunctionExceptionWhenGivenBadQuery() {
     LuceneService luceneService = LuceneServiceProvider.get(cache);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/31096fbf/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxFieldMapperJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxFieldMapperJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxFieldMapperJUnitTest.java
index 278e818..9726df5 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxFieldMapperJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PdxFieldMapperJUnitTest.java
@@ -78,4 +78,24 @@ public class PdxFieldMapperJUnitTest {
     assertEquals("a", doc.getField("s").stringValue());
     assertEquals(5, doc.getField("i").numericValue());
   }
+  
+  @Test
+  public void testNullField() {
+    String[] fields = new String[] {"s", "i"};
+    PdxLuceneSerializer mapper = new PdxLuceneSerializer(fields);
+    
+    PdxInstance i = mock(PdxInstance.class);
+    
+    when(i.hasField("s")).thenReturn(true);
+    when(i.hasField("i")).thenReturn(true);
+    when(i.getField("s")).thenReturn("a");
+    when(i.getField("i")).thenReturn(null);
+    
+    Document doc = new Document();
+    mapper.toDocument(i, doc);
+    
+    assertEquals(1, doc.getFields().size());
+    assertEquals("a", doc.getField("s").stringValue());
+    assertNull(doc.getField("i"));
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/31096fbf/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionFieldMapperJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionFieldMapperJUnitTest.java
b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionFieldMapperJUnitTest.java
index c187022..7727718 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionFieldMapperJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/ReflectionFieldMapperJUnitTest.java
@@ -80,4 +80,20 @@ public class ReflectionFieldMapperJUnitTest {
     assertEquals("a", doc.getField("s").stringValue());
     assertEquals("b", doc.getField("s2").stringValue());
   }
+  
+  @Test
+  public void testNullField() {
+
+    String[] fields = new String[] {"s", "o", "s2"};
+    ReflectionLuceneSerializer mapper = new ReflectionLuceneSerializer(Type2.class, fields);
+    
+    Type2 t = new Type2("a", 1, 2L, 3.0, 4.0f, null);
+    
+    Document doc = new Document();
+    mapper.toDocument(t, doc);
+    
+    assertEquals(1, doc.getFields().size());
+    assertEquals("a", doc.getField("s").stringValue());
+    assertNull(doc.getField("s2"));
+  }
 }


Mime
View raw message