lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject svn commit: r1489677 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
Date Wed, 05 Jun 2013 00:50:54 GMT
Author: sarowe
Date: Wed Jun  5 00:50:54 2013
New Revision: 1489677

URL: http://svn.apache.org/r1489677
Log:
SOLR-4891: JsonLoader should preserve field value types from the JSON content stream (merged
r1489676)

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1489677&r1=1489676&r2=1489677&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Wed Jun  5 00:50:54 2013
@@ -90,6 +90,9 @@ Bug Fixes
 * SOLR-4863: Removed non-existent attribute sourceId from dynamic JMX stats
   to fix AttributeNotFoundException (suganuma, hossman via shalin)
 
+* SOLR-4891: JsonLoader should preserve field value types from the JSON content stream.
+  (Steve Rowe)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java?rev=1489677&r1=1489676&r2=1489677&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/handler/loader/JsonLoader.java
Wed Jun  5 00:50:54 2013
@@ -512,11 +512,13 @@ public class JsonLoader extends ContentS
         case JSONParser.STRING:
           return parser.getString();
         case JSONParser.LONG:
+          return parser.getLong();
         case JSONParser.NUMBER:
+          return parser.getDouble();
         case JSONParser.BIGNUMBER:
-          return parser.getNumberChars().toString();
+          return (new ObjectBuilder(parser)).getBigNumber();
         case JSONParser.BOOLEAN:
-          return Boolean.toString(parser.getBoolean()); // for legacy reasons, single values
s are expected to be strings
+          return parser.getBoolean();
         case JSONParser.NULL:
           parser.getNull();
           return null;

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java?rev=1489677&r1=1489676&r2=1489677&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/handler/JsonLoaderTest.java
Wed Jun  5 00:50:54 2013
@@ -31,6 +31,9 @@ import org.apache.solr.update.processor.
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
 import java.util.Map;
 
 public class JsonLoaderTest extends SolrTestCaseJ4 {
@@ -236,6 +239,155 @@ public class JsonLoaderTest extends Solr
         ,"/response/docs/[0]=={'foo2_s':['hi','there']}"
     );
   }
+  
+  @Test
+  public void testBooleanValuesInAdd() throws Exception {
+    String str = "{'add':[{'id':'1','b1':true,'b2':false,'b3':[false,true]}]}".replace('\'',
'"');
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
+
+    assertEquals(1, p.addCommands.size());
+
+    AddUpdateCommand add = p.addCommands.get(0);
+    SolrInputDocument d = add.solrDoc;
+    SolrInputField f = d.getField("b1");
+    assertEquals(Boolean.TRUE, f.getValue());
+    f = d.getField("b2");
+    assertEquals(Boolean.FALSE, f.getValue());
+    f = d.getField("b3");
+    assertEquals(2, ((List)f.getValue()).size());
+    assertEquals(Boolean.FALSE, ((List)f.getValue()).get(0));
+    assertEquals(Boolean.TRUE, ((List)f.getValue()).get(1));
+
+    req.close();
+  }
+
+  @Test
+  public void testIntegerValuesInAdd() throws Exception {
+    String str = "{'add':[{'id':'1','i1':256,'i2':-5123456789,'i3':[0,1]}]}".replace('\'',
'"');
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
+
+    assertEquals(1, p.addCommands.size());
+
+    AddUpdateCommand add = p.addCommands.get(0);
+    SolrInputDocument d = add.solrDoc;
+    SolrInputField f = d.getField("i1");
+    assertEquals(256L, f.getValue());
+    f = d.getField("i2");
+    assertEquals(-5123456789L, f.getValue());
+    f = d.getField("i3");
+    assertEquals(2, ((List)f.getValue()).size());
+    assertEquals(0L, ((List)f.getValue()).get(0));
+    assertEquals(1L, ((List)f.getValue()).get(1));
+
+    req.close();
+  }
+
+
+  @Test
+  public void testDecimalValuesInAdd() throws Exception {
+    String str = "{'add':[{'id':'1','d1':256.78,'d2':-5123456789.0,'d3':0.0,'d3':1.0,'d4':1.7E-10}]}".replace('\'',
'"');
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
+
+    assertEquals(1, p.addCommands.size());
+
+    AddUpdateCommand add = p.addCommands.get(0);
+    SolrInputDocument d = add.solrDoc;
+    SolrInputField f = d.getField("d1");
+    assertEquals(256.78, f.getValue());
+    f = d.getField("d2");
+    assertEquals(-5123456789.0, f.getValue());
+    f = d.getField("d3");
+    assertEquals(2, ((List)f.getValue()).size());
+    assertTrue(((List)f.getValue()).contains(0.0));
+    assertTrue(((List) f.getValue()).contains(1.0));
+    f = d.getField("d4");
+    assertEquals(1.7E-10, f.getValue());
+
+    req.close();
+  }
+
+  @Test
+  public void testBigDecimalValuesInAdd() throws Exception {
+    String str = ("{'add':[{'id':'1','bd1':0.12345678901234567890123456789012345,"
+                 + "'bd2':12345678901234567890.12345678901234567890,'bd3':0.012345678901234567890123456789012345,"
+                 + "'bd3':123456789012345678900.012345678901234567890}]}").replace('\'',
'"');
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
+
+    assertEquals(1, p.addCommands.size());
+
+    AddUpdateCommand add = p.addCommands.get(0);
+    SolrInputDocument d = add.solrDoc;
+    SolrInputField f = d.getField("bd1");                        
+    assertTrue(f.getValue() instanceof BigDecimal);
+    assertEquals(new BigDecimal("0.12345678901234567890123456789012345"), f.getValue());
+    f = d.getField("bd2");
+    assertTrue(f.getValue() instanceof BigDecimal);
+    assertEquals(new BigDecimal("12345678901234567890.12345678901234567890"), f.getValue());
+    f = d.getField("bd3");
+    assertEquals(2, ((List)f.getValue()).size());
+    assertTrue(((List)f.getValue()).contains(new BigDecimal("0.012345678901234567890123456789012345")));
+    assertTrue(((List)f.getValue()).contains(new BigDecimal("123456789012345678900.012345678901234567890")));
+
+    req.close();
+  }
+
+  @Test
+  public void testBigIntegerValuesInAdd() throws Exception {
+    String str = ("{'add':[{'id':'1','bi1':123456789012345678901,'bi2':1098765432109876543210,"
+                 + "'bi3':[1234567890123456789012,10987654321098765432109]}]}").replace('\'',
'"');
+    SolrQueryRequest req = req();
+    SolrQueryResponse rsp = new SolrQueryResponse();
+    BufferingRequestProcessor p = new BufferingRequestProcessor(null);
+    JsonLoader loader = new JsonLoader();
+    loader.load(req, rsp, new ContentStreamBase.StringStream(str), p);
+
+    assertEquals(1, p.addCommands.size());
+
+    AddUpdateCommand add = p.addCommands.get(0);
+    SolrInputDocument d = add.solrDoc;
+    SolrInputField f = d.getField("bi1");
+    assertTrue(f.getValue() instanceof BigInteger);
+    assertEquals(new BigInteger("123456789012345678901"), f.getValue());
+    f = d.getField("bi2");
+    assertTrue(f.getValue() instanceof BigInteger);
+    assertEquals(new BigInteger("1098765432109876543210"), f.getValue());
+    f = d.getField("bi3");
+    assertEquals(2, ((List)f.getValue()).size());
+    assertTrue(((List)f.getValue()).contains(new BigInteger("1234567890123456789012")));
+    assertTrue(((List)f.getValue()).contains(new BigInteger("10987654321098765432109")));
+
+    req.close();
+  }
+
+
+  @Test
+  public void testAddNonStringValues() throws Exception {
+    // BigInteger and BigDecimal should be typed as strings, since there is no direct support
for them
+    updateJ(("[{'id':'1','boolean_b':false,'long_l':19,'double_d':18.6,'big_integer_s':12345678901234567890,"
+        +"      'big_decimal_s':0.1234567890123456789012345}]").replace('\'', '"'), params("commit","true"));
+    assertJQ(req("q","id:1", "fl","boolean_b,long_l,double_d,big_integer_s,big_decimal_s")
+        ,"/response/docs/[0]=={'boolean_b':[false],'long_l':[19],'double_d':[18.6],"
+                             +"'big_integer_s':['12345678901234567890'],"
+                             +"'big_decimal_s':['0.1234567890123456789012345']}]}"
+    );
+  }
+
 
   // The delete syntax was both extended for simplification in 4.0
   @Test



Mime
View raw message