lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [44/48] lucene-solr:jira/http2: SOLR-12615: HashQParserPlugin won't throw an NPE for string hash key and documents with empty value
Date Mon, 06 Aug 2018 04:16:17 GMT
SOLR-12615: HashQParserPlugin won't throw an NPE for string hash key and documents with empty
value


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

Branch: refs/heads/jira/http2
Commit: 592899a419c2a15e75f73e906fa61b7e922c9830
Parents: b33df4e
Author: Varun Thacker <varun@apache.org>
Authored: Sat Aug 4 14:31:07 2018 -0700
Committer: Varun Thacker <varun@apache.org>
Committed: Sat Aug 4 14:32:36 2018 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  5 ++++
 .../apache/solr/search/HashQParserPlugin.java   |  4 +--
 .../solr/search/TestHashQParserPlugin.java      | 30 +++++++++++++++++++-
 3 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/592899a4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3d9c68c..605e837 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -207,6 +207,11 @@ Bug Fixes
 
 * SOLR-12594: MetricsHistoryHandler.getOverseerLeader fails when hostname contains hyphen.
(ab)
 
+* SOLR-12615: HashQParserPlugin will no longer throw an NPE if the hash key field is a string
when there are documents
+  with empty values. All documents with empty values ( string , numeric ) will be processed
by worker=0
+  This would fix the NPE when using the search stream with partitionKeys. (Varun Thacker)
+
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/592899a4/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
index 8832bb7..bd8f425 100644
--- a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
@@ -297,7 +297,7 @@ public class HashQParserPlugin extends QParserPlugin {
       if (doc == values.docID()) {
         ref = values.binaryValue();
       } else {
-        ref = null;
+        ref = new BytesRef(); // EMPTY_BYTES . worker=0 will always process empty values
       }
       this.fieldType.indexedToReadable(ref, charsRefBuilder);
       CharsRef charsRef = charsRefBuilder.get();
@@ -327,7 +327,7 @@ public class HashQParserPlugin extends QParserPlugin {
       if (valuesDocID == doc) {
         l = values.longValue();
       } else {
-        l = 0;
+        l = 0; //worker=0 will always process empty values
       }
       return Longs.hashCode(l);
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/592899a4/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
index 3f320ce..6f68906 100644
--- a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
+++ b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
@@ -54,6 +54,34 @@ public class TestHashQParserPlugin extends SolrTestCaseJ4 {
     }
   }
 
+  @Test
+  public void testHashPartitionWithEmptyValues() throws Exception {
+
+    assertU(adoc("id", "1", "a_s", "one", "a_i" , "1"));
+    assertU(adoc("id", "2", "a_s", "one", "a_i" , "1"));
+    assertU(adoc("id", "3"));
+    assertU(adoc("id", "4"));
+    assertU(commit());
+
+    //Test with string hash
+    ModifiableSolrParams params = new ModifiableSolrParams();
+    params.add("q", "*:*");
+    params.add("fq", "{!hash worker=0 workers=1 cost="+getCost(random())+"}");
+    params.add("partitionKeys", "a_s");
+    params.add("wt", "xml");
+    String response = h.query(req(params));
+    h.validateXPath(response, "//*[@numFound='4']");
+
+    //Test with int hash
+    params = new ModifiableSolrParams();
+    params.add("q", "*:*");
+    params.add("fq", "{!hash worker=0 workers=1 cost="+getCost(random())+"}");
+    params.add("partitionKeys", "a_i");
+    params.add("wt", "xml");
+    response = h.query(req(params));
+    h.validateXPath(response, "//*[@numFound='4']");
+  }
+
 
   @Test
   public void testHashPartition() throws Exception {
@@ -62,7 +90,7 @@ public class TestHashQParserPlugin extends SolrTestCaseJ4 {
     Random random = random();
     HashSet<String> set = new HashSet();
 
-    for(int i=0; i<50; i++) {
+    for (int i=0; i<50; i++) {
       int v = random.nextInt(1000000);
       String val = Integer.toString(v);
       if(!set.contains(val)){


Mime
View raw message