lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject lucene-solr:branch_7x: SOLR-10668: fix NPE at sort=childfield(..) .. on absent values
Date Thu, 06 Jul 2017 07:48:48 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 17245c2e5 -> 986175915


SOLR-10668: fix NPE at sort=childfield(..) .. on absent values


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

Branch: refs/heads/branch_7x
Commit: 986175915927ee2bbd971340f858601c86b3c676
Parents: 17245c2
Author: Mikhail Khludnev <mkhl@apache.org>
Authored: Wed Jul 5 22:53:14 2017 +0300
Committer: Mikhail Khludnev <mkhl@apache.org>
Committed: Thu Jul 6 10:45:56 2017 +0300

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +-
 .../join/ChildFieldValueSourceParser.java       |  3 +-
 .../search/join/TestCloudNestedDocsSort.java    | 32 ++++++++++++--------
 .../solr/search/join/TestNestedDocsSort.java    |  5 +++
 4 files changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/98617591/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2765b53..c06c0c6 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -45,7 +45,7 @@ New Features
 Bug Fixes
 ----------------------
 
-(No Changes)
+* SOLR-10668: fix NPE at sort=childfield(..) .. on absent values (Mikhail Khludnev)
 
 Optimizations
 ----------------------

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/98617591/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
b/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
index a31d36f..fcd21b3 100644
--- a/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/join/ChildFieldValueSourceParser.java
@@ -65,7 +65,8 @@ public class ChildFieldValueSourceParser extends ValueSourceParser {
 
       @Override
       public String value(int slot) {
-        return byteRefs.value(slot).utf8ToString();
+        final BytesRef value = byteRefs.value(slot);
+        return value!=null ? value.utf8ToString() : null;
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/98617591/solr/core/src/test/org/apache/solr/search/join/TestCloudNestedDocsSort.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/join/TestCloudNestedDocsSort.java b/solr/core/src/test/org/apache/solr/search/join/TestCloudNestedDocsSort.java
index 5cd49aa..9bae53c 100644
--- a/solr/core/src/test/org/apache/solr/search/join/TestCloudNestedDocsSort.java
+++ b/solr/core/src/test/org/apache/solr/search/join/TestCloudNestedDocsSort.java
@@ -39,8 +39,6 @@ import org.apache.solr.common.cloud.ZkStateReader;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import com.carrotsearch.randomizedtesting.annotations.Repeat;
-
 public class TestCloudNestedDocsSort extends SolrCloudTestCase {
 
   private static ArrayList<String> vals = new ArrayList<>();
@@ -78,7 +76,8 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
     
     {
       List<SolrInputDocument> docs = new ArrayList<>();
-      int parentsNum = 10+random().nextInt(20);
+      int parentsNum = 10 +random().nextInt(20)
+          ;
       for (int i=0; i<parentsNum || (matchingParent==null ||matchingChild==null); i++)
{
         final String parentTieVal = "" + random().nextInt(5);
         final String parentId = ""+random().nextInt();
@@ -93,9 +92,11 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
           SolrInputDocument child = new SolrInputDocument("id", ""+random().nextInt(),
               "type_s", "child",
               "parentTie_s1", parentTieVal,
-              "val_s1", Integer.toString(random().nextInt(1000), Character.MAX_RADIX)+""
,
               "parent_id_s1", parentId);
           child.addField("parentFilter_s", parentFilter);
+          if (usually()) {
+            child.addField( "val_s1", Integer.toString(random().nextInt(1000), Character.MAX_RADIX)+""
);
+          }
           final List<String> chVals = addValsField(child, "childFilter_s");
           parent.addChildDocument(child );
 
@@ -115,7 +116,7 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
     }
   }
 
-  @Test @Repeat(iterations=2)
+  @Test 
   public void test() throws SolrServerException, IOException {
     final boolean asc = random().nextBoolean();
     final String dir = asc ? "asc": "desc";
@@ -134,10 +135,17 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
 
     final QueryResponse children = client.query(q);
     
-    final SolrQuery bjq = new SolrQuery("q", "{!parent which=type_s:parent}(+type_s:child^=0
"+parentFilter+" "+
-        childFilter+")",
-       "sort", sortClause.replace("val_s1 ", "childfield(val_s1)"),
-        "rows", ""+maxDocs, "fl", fl);
+    final SolrQuery bjq = random().nextBoolean() ? 
+         new SolrQuery(// top level bjq
+           "q", "{!parent which=type_s:parent}(+type_s:child^=0 "+parentFilter+" "+ childFilter+")",
+           "sort", sortClause.replace("val_s1", "childfield(val_s1)"),
+           "rows", ""+maxDocs, "fl", fl)
+         :
+        new SolrQuery(// same bjq as a subordinate clause
+           "q", "+type_s:parent "+parentFilter+" +{!v=$parentcaluse}",
+           "parentcaluse","{!parent which=type_s:parent v='"+(childFilter).replace("+", "")+"'}",
+           "sort", sortClause.replace("val_s1", "childfield(val_s1,$parentcaluse)"),
+           "rows", ""+maxDocs, "fl", fl);
 
     final QueryResponse parents = client.query(bjq);
     
@@ -153,11 +161,11 @@ public class TestCloudNestedDocsSort extends SolrCloudTestCase {
           final String actParentId = ""+ parent.get("id");
           if (!actParentId.equals(parentId)) {
             final String chDump = children.toString().replace("SolrDocument","\nSolrDocument");
-            System.out.println("\n\n"+chDump.substring(0,5000)+"\n\n");
-            System.out.println("\n\n"+chDump
+            System.out.println("\n\n"+chDump+"\n\n");
+            System.out.println("\n\n"+parents.toString().replace("SolrDocument","\nSolrDocument")
                 +"\n\n");
           }
-          assertEquals(actParentId, parentId);
+          assertEquals(""+child+"\n"+parent,actParentId, parentId);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/98617591/solr/core/src/test/org/apache/solr/search/join/TestNestedDocsSort.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/join/TestNestedDocsSort.java b/solr/core/src/test/org/apache/solr/search/join/TestNestedDocsSort.java
index c635d7c..8c7ee2a 100644
--- a/solr/core/src/test/org/apache/solr/search/join/TestNestedDocsSort.java
+++ b/solr/core/src/test/org/apache/solr/search/join/TestNestedDocsSort.java
@@ -85,6 +85,11 @@ public class TestNestedDocsSort extends SolrTestCaseJ4 {
       parse("childfield(name_s1,$q)");
     }
     
+    @Test
+    public void testOmitSpaceinFrontOfOrd(){
+      parseAssertEq("childfield(name_s1,$q)asc", "childfield(name_s1,$q) asc");
+    }
+    
     private void parseAssertEq(String sortField, String sortField2) {
       assertEq(parse(sortField), parse(sortField2));
     }


Mime
View raw message