You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by va...@apache.org on 2018/08/05 18:28:10 UTC
lucene-solr:branch_7x: SOLR-12615: HashQParserPlugin won't throw an
NPE for string hash key and documents with empty value
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 7a14a1a7e -> a862e432e
SOLR-12615: HashQParserPlugin won't throw an NPE for string hash key and documents with empty value
(cherry picked from commit 592899a)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a862e432
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a862e432
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a862e432
Branch: refs/heads/branch_7x
Commit: a862e432ec68a22a2b784d8d1226a6ee36918c22
Parents: 7a14a1a
Author: Varun Thacker <va...@apache.org>
Authored: Sat Aug 4 14:31:07 2018 -0700
Committer: Varun Thacker <va...@apache.org>
Committed: Sun Aug 5 11:08:30 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/a862e432/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 86c4cd7..6e85ae8 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -174,6 +174,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/a862e432/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 dc75289..517c507 100644
--- a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
@@ -295,7 +295,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();
@@ -325,7 +325,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/a862e432/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)){