lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsmi...@apache.org
Subject lucene-solr:branch_7x: SOLR-12362: JSON parsing: upgrade to List on end of array not start. And fix TestJsonRecordReader assumptions RE null keys
Date Fri, 15 Jun 2018 04:47:48 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x b0581ecb1 -> daf773f46


SOLR-12362: JSON parsing: upgrade to List on end of array not start. And fix TestJsonRecordReader
assumptions RE null keys

(cherry picked from commit 4799bc5)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/daf773f4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/daf773f4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/daf773f4

Branch: refs/heads/branch_7x
Commit: daf773f4635b6570d5dc05576bb6ff6e63b63fd8
Parents: b0581ec
Author: David Smiley <dsmiley@apache.org>
Authored: Fri Jun 15 00:46:17 2018 -0400
Committer: David Smiley <dsmiley@apache.org>
Committed: Fri Jun 15 00:47:40 2018 -0400

----------------------------------------------------------------------
 .../apache/solr/common/util/JsonRecordReader.java   | 16 ++++++++++------
 .../solr/common/util/TestJsonRecordReader.java      | 10 +++-------
 2 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/daf773f4/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
index 7f93bc4..f66c88e 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java
@@ -348,12 +348,17 @@ public class JsonRecordReader {
           } else if (event == ARRAY_START) {
             for (; ; ) {
               event = parser.nextEvent();
-              if (event == ARRAY_END) break;
-              if (event == OBJECT_START) {
-                // if single item in array will still be added as array
-                if(!values.containsKey(name)) {
-                  values.put(name, new ArrayList<>());
+              if (event == ARRAY_END) {
+                // ensure that the value is of type List
+                final Object val = values.get(name);
+                if (val != null && !(val instanceof List)) {
+                  final ArrayList listVal = new ArrayList(1);
+                  listVal.add(val);
+                  values.put(name, listVal);
                 }
+                break;
+              }
+              if (event == OBJECT_START) {
                 walkObject();
               }
             }
@@ -437,7 +442,6 @@ public class JsonRecordReader {
           for (String fld : valuesAddedinThisFrame) {
             values.remove(fld);
           }
-          values.remove(null);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/daf773f4/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java b/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java
index da75a43..9b10970 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java
@@ -18,7 +18,6 @@ package org.apache.solr.common.util;
 
 import java.io.IOException;
 import java.io.StringReader;
-import java.lang.invoke.MethodHandles;
 import java.lang.ref.WeakReference;
 import java.util.Arrays;
 import java.util.Collections;
@@ -29,12 +28,9 @@ import java.util.concurrent.atomic.AtomicReference;
 import org.apache.commons.lang.StringUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.util.RecordingJSONParser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 public class TestJsonRecordReader extends SolrTestCaseJ4 {
-  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public void testOneLevelSplit() throws IOException {
     String json = "{\n" +
@@ -281,7 +277,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
     JsonRecordReader streamer = JsonRecordReader.getInst("/|/a/b", Arrays.asList("/a/x",
"/a/b/*"));
     streamer.streamRecords(new StringReader(json), (record, path) -> {
       assertEquals(record.get("x"), "y");
-      assertEquals(((Map) record.get(null)).get("c"), "d");
+      assertEquals(((Map) record.get("b")).get("c"), "d");
     });
     json = "{a:{" +
         "b:[{c:c1, e:e1},{c:c2, e :e2, d:{p:q}}]," +
@@ -289,7 +285,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
         "}}";
     streamer.streamRecords(new StringReader(json), (record, path) -> {
       assertEquals(record.get("x"), "y");
-      List l = (List) record.get(null);
+      List l = (List) record.get("b");
       Map m = (Map) l.get(0);
       assertEquals(m.get("c"), "c1");
       assertEquals(m.get("e"), "e1");
@@ -300,7 +296,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {
     streamer = JsonRecordReader.getInst("/|/a/b", Arrays.asList("$FQN:/**"));
     streamer.streamRecords(new StringReader(json), (record, path) -> {
       assertEquals(record.get("a.x"), "y");
-      List l = (List) record.get(null);
+      List l = (List) record.get("b");
       Map m = (Map) l.get(0);
       assertEquals(m.get("c"), "c1");
       assertEquals(m.get("e"), "e1");


Mime
View raw message