You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/08/21 01:31:15 UTC
[48/50] [abbrv] lucene-solr:jira/http2: SOLR-12683: HashQuery will
throw an exception if more than 4 partitionKeys is specified. Earlier after
the 4th partitionKey the keys would be silently ignored.
SOLR-12683: HashQuery will throw an exception if more than 4 partitionKeys is specified. Earlier after the 4th partitionKey the keys would be silently ignored.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/5eab1c3c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5eab1c3c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5eab1c3c
Branch: refs/heads/jira/http2
Commit: 5eab1c3c688a0d8db650c657567f197fb3dcf181
Parents: 66d500b
Author: Varun Thacker <va...@apache.org>
Authored: Mon Aug 20 15:21:19 2018 -0700
Committer: Varun Thacker <va...@apache.org>
Committed: Mon Aug 20 15:21:19 2018 -0700
----------------------------------------------------------------------
solr/CHANGES.txt | 3 ++
.../apache/solr/search/HashQParserPlugin.java | 19 ++++++------
.../solr/search/TestHashQParserPlugin.java | 31 ++++++++++++++++++++
3 files changed, 44 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5eab1c3c/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e5d13df..1303062 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -251,6 +251,9 @@ Bug Fixes
* SOLR-12598: Do not fetch non-stored fields (Nikolay Khitrin, Erick Erickson)
+* SOLR-12683: HashQuery will throw an exception if more than 4 partitionKeys is specified.
+ Earlier after the 4th partitionKey the keys would be silently ignored. (Varun Thacker)
+
Optimizations
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5eab1c3c/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 a499a10..209f2bd 100644
--- a/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/HashQParserPlugin.java
@@ -73,15 +73,18 @@ public class HashQParserPlugin extends QParserPlugin {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "workers needs to be more than 1");
}
int worker = localParams.getInt("worker", 0);
- String keys = params.get("partitionKeys");
- keys = keys.replace(" ", "");
+ String keyParam = params.get("partitionKeys");
+ String[] keys = keyParam.replace(" ", "").split(",");
+ if (keys.length > 4) {
+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "HashQuery supports upto 4 partitionKeys");
+ }
return new HashQuery(keys, workers, worker);
}
}
private static class HashQuery extends ExtendedQueryBase implements PostFilter {
- private String keysParam;
+ private String[] keys;
private int workers;
private int worker;
@@ -95,7 +98,7 @@ public class HashQParserPlugin extends QParserPlugin {
public int hashCode() {
return classHash() +
- 31 * keysParam.hashCode() +
+ 31 * keys.hashCode() +
31 * workers +
31 * worker;
}
@@ -106,13 +109,13 @@ public class HashQParserPlugin extends QParserPlugin {
}
private boolean equalsTo(HashQuery other) {
- return keysParam.equals(other.keysParam) &&
+ return keys.equals(other.keys) &&
workers == other.workers &&
worker == other.worker;
}
- public HashQuery(String keysParam, int workers, int worker) {
- this.keysParam = keysParam;
+ public HashQuery(String[] keys, int workers, int worker) {
+ this.keys = keys;
this.workers = workers;
this.worker = worker;
}
@@ -120,7 +123,6 @@ public class HashQParserPlugin extends QParserPlugin {
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
- String[] keys = keysParam.split(",");
SolrIndexSearcher solrIndexSearcher = (SolrIndexSearcher)searcher;
IndexReaderContext context = solrIndexSearcher.getTopReaderContext();
@@ -224,7 +226,6 @@ public class HashQParserPlugin extends QParserPlugin {
}
public DelegatingCollector getFilterCollector(IndexSearcher indexSearcher) {
- String[] keys = keysParam.split(",");
HashKey[] hashKeys = new HashKey[keys.length];
SolrIndexSearcher searcher = (SolrIndexSearcher)indexSearcher;
IndexSchema schema = searcher.getSchema();
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5eab1c3c/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 06c2097..03e68de 100644
--- a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
+++ b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java
@@ -18,6 +18,7 @@ package org.apache.solr.search;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -55,6 +56,36 @@ public class TestHashQParserPlugin extends SolrTestCaseJ4 {
}
@Test
+ public void testManyHashPartitions() throws Exception {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.add("q", "*:*");
+ params.add("fq", "{!hash worker=0 workers=2 cost="+getCost(random())+"}");
+ params.add("partitionKeys", "a_i,a_s,a_i,a_s");
+ params.add("wt", "xml");
+ String response = h.query(req(params));
+ h.validateXPath(response, "//*[@numFound='0']");
+
+ params = new ModifiableSolrParams();
+ params.add("q", "*:*");
+ params.add("fq", "{!hash worker=0 workers=2 cost="+getCost(random())+"}");
+ params.add("partitionKeys", "a_i,a_s,a_i,a_s,a_i");
+ params.add("wt", "xml");
+ ModifiableSolrParams finalParams = params;
+ expectThrows(SolrException.class, () -> h.query(req(finalParams)));
+ }
+
+ @Test
+ public void testLessWorkers() {
+ ModifiableSolrParams 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");
+ ModifiableSolrParams finalParams = params;
+ expectThrows(SolrException.class, () -> h.query(req(finalParams)));
+ }
+
+ @Test
public void testHashPartitionWithEmptyValues() throws Exception {
assertU(adoc("id", "1", "a_s", "one", "a_i" , "1"));