Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AD6C3200C00 for ; Tue, 3 Jan 2017 23:30:42 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AC009160B20; Tue, 3 Jan 2017 22:30:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A8569160B48 for ; Tue, 3 Jan 2017 23:30:41 +0100 (CET) Received: (qmail 689 invoked by uid 500); 3 Jan 2017 22:30:40 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 593 invoked by uid 99); 3 Jan 2017 22:30:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jan 2017 22:30:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 54614DFD9D; Tue, 3 Jan 2017 22:30:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jbernste@apache.org To: commits@lucene.apache.org Date: Tue, 03 Jan 2017 22:30:41 -0000 Message-Id: <7e70adb22e1643ed99da2e5df686f144@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/5] lucene-solr:branch_6x: SOLR-8530: Add tests from the HavingStream archived-at: Tue, 03 Jan 2017 22:30:42 -0000 SOLR-8530: Add tests from the HavingStream Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/297b1789 Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/297b1789 Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/297b1789 Branch: refs/heads/branch_6x Commit: 297b1789092f4f9b3a2cfb91da397e5034708486 Parents: 2f7d6fc Author: Joel Bernstein Authored: Fri Dec 16 11:26:55 2016 -0500 Committer: Joel Bernstein Committed: Tue Jan 3 17:13:13 2017 -0500 ---------------------------------------------------------------------- .../org/apache/solr/handler/StreamHandler.java | 19 +- .../solrj/io/stream/StreamExpressionTest.java | 201 +++++++++++++++++++ 2 files changed, 219 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b1789/solr/core/src/java/org/apache/solr/handler/StreamHandler.java ---------------------------------------------------------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java index 639937d..dd79462 100644 --- a/solr/core/src/java/org/apache/solr/handler/StreamHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/StreamHandler.java @@ -31,9 +31,17 @@ import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.StreamComparator; import org.apache.solr.client.solrj.io.graph.GatherNodesStream; import org.apache.solr.client.solrj.io.graph.ShortestPathStream; +import org.apache.solr.client.solrj.io.ops.AndOperation; import org.apache.solr.client.solrj.io.ops.ConcatOperation; import org.apache.solr.client.solrj.io.ops.DistinctOperation; +import org.apache.solr.client.solrj.io.ops.EqualsOperation; +import org.apache.solr.client.solrj.io.ops.GreaterThanEqualToOperation; +import org.apache.solr.client.solrj.io.ops.GreaterThanOperation; import org.apache.solr.client.solrj.io.ops.GroupOperation; +import org.apache.solr.client.solrj.io.ops.LessThanEqualToOperation; +import org.apache.solr.client.solrj.io.ops.LessThanOperation; +import org.apache.solr.client.solrj.io.ops.NotOperation; +import org.apache.solr.client.solrj.io.ops.OrOperation; import org.apache.solr.client.solrj.io.ops.ReplaceOperation; import org.apache.solr.client.solrj.io.stream.*; import org.apache.solr.client.solrj.io.stream.expr.Explanation; @@ -155,7 +163,16 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware, // stream reduction operations .withFunctionName("group", GroupOperation.class) - .withFunctionName("distinct", DistinctOperation.class); + .withFunctionName("distinct", DistinctOperation.class) + .withFunctionName("having", HavingStream.class) + .withFunctionName("and", AndOperation.class) + .withFunctionName("or", OrOperation.class) + .withFunctionName("not", NotOperation.class) + .withFunctionName("gt", GreaterThanOperation.class) + .withFunctionName("lt", LessThanOperation.class) + .withFunctionName("eq", EqualsOperation.class) + .withFunctionName("lteq", LessThanEqualToOperation.class) + .withFunctionName("gteq", GreaterThanEqualToOperation.class); // This pulls all the overrides and additions from the config List pluginInfos = core.getSolrConfig().getPluginInfos(Expressible.class.getName()); http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/297b1789/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java ---------------------------------------------------------------------- diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java index 1316af4..fd088f1 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java @@ -33,8 +33,16 @@ import org.apache.solr.client.solrj.io.SolrClientCache; import org.apache.solr.client.solrj.io.Tuple; import org.apache.solr.client.solrj.io.comp.ComparatorOrder; import org.apache.solr.client.solrj.io.comp.FieldComparator; +import org.apache.solr.client.solrj.io.ops.AndOperation; import org.apache.solr.client.solrj.io.ops.ConcatOperation; +import org.apache.solr.client.solrj.io.ops.EqualsOperation; +import org.apache.solr.client.solrj.io.ops.GreaterThanEqualToOperation; +import org.apache.solr.client.solrj.io.ops.GreaterThanOperation; import org.apache.solr.client.solrj.io.ops.GroupOperation; +import org.apache.solr.client.solrj.io.ops.LessThanEqualToOperation; +import org.apache.solr.client.solrj.io.ops.LessThanOperation; +import org.apache.solr.client.solrj.io.ops.NotOperation; +import org.apache.solr.client.solrj.io.ops.OrOperation; import org.apache.solr.client.solrj.io.ops.ReplaceOperation; import org.apache.solr.client.solrj.io.stream.expr.StreamExpression; import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParser; @@ -803,6 +811,199 @@ public class StreamExpressionTest extends SolrCloudTestCase { } + + @Test + public void testHavingStream() throws Exception { + + SolrClientCache solrClientCache = new SolrClientCache(); + + new UpdateRequest() + .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1", "subject", "blah blah blah 0") + .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2", "subject", "blah blah blah 2") + .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "subject", "blah blah blah 3") + .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "subject", "blah blah blah 4") + .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5", "subject", "blah blah blah 1") + .add(id, "5", "a_s", "hello3", "a_i", "5", "a_f", "6", "subject", "blah blah blah 5") + .add(id, "6", "a_s", "hello4", "a_i", "6", "a_f", "7", "subject", "blah blah blah 6") + .add(id, "7", "a_s", "hello3", "a_i", "7", "a_f", "8", "subject", "blah blah blah 7") + .add(id, "8", "a_s", "hello3", "a_i", "8", "a_f", "9", "subject", "blah blah blah 8") + .add(id, "9", "a_s", "hello0", "a_i", "9", "a_f", "10", "subject", "blah blah blah 9") + .commit(cluster.getSolrClient(), COLLECTIONORALIAS); + + TupleStream stream; + List tuples; + + StreamFactory factory = new StreamFactory() + .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress()) + .withFunctionName("search", CloudSolrStream.class) + .withFunctionName("having", HavingStream.class) + .withFunctionName("and", AndOperation.class) + .withFunctionName("or", OrOperation.class) + .withFunctionName("not", NotOperation.class) + .withFunctionName("gt", GreaterThanOperation.class) + .withFunctionName("lt", LessThanOperation.class) + .withFunctionName("eq", EqualsOperation.class) + .withFunctionName("lteq", LessThanEqualToOperation.class) + .withFunctionName("gteq", GreaterThanEqualToOperation.class); + + stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), eq(a_i, 9))"); + StreamContext context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 1); + Tuple t = tuples.get(0); + assertTrue(t.getString("id").equals("9")); + + stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),lt(a_i, 10)))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 1); + t = tuples.get(0); + assertTrue(t.getString("id").equals("9")); + + stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), or(eq(a_i, 9),eq(a_i, 8)))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 2); + t = tuples.get(0); + assertTrue(t.getString("id").equals("8")); + + t = tuples.get(1); + assertTrue(t.getString("id").equals("9")); + + + stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(eq(a_i, 9),not(eq(a_i, 9))))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 0); + + + stream = factory.constructStream("having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\"), and(lteq(a_i, 9), gteq(a_i, 8)))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + System.out.println("####Tuples:"+tuples.size()); + assert(tuples.size() == 2); + + t = tuples.get(0); + assertTrue(t.getString("id").equals("8")); + + t = tuples.get(1); + assertTrue(t.getString("id").equals("9")); + + solrClientCache.close(); + } + + + @Test + public void testParallelHavingStream() throws Exception { + + SolrClientCache solrClientCache = new SolrClientCache(); + + new UpdateRequest() + .add(id, "0", "a_s", "hello0", "a_i", "0", "a_f", "1", "subject", "blah blah blah 0") + .add(id, "2", "a_s", "hello0", "a_i", "2", "a_f", "2", "subject", "blah blah blah 2") + .add(id, "3", "a_s", "hello3", "a_i", "3", "a_f", "3", "subject", "blah blah blah 3") + .add(id, "4", "a_s", "hello4", "a_i", "4", "a_f", "4", "subject", "blah blah blah 4") + .add(id, "1", "a_s", "hello0", "a_i", "1", "a_f", "5", "subject", "blah blah blah 1") + .add(id, "5", "a_s", "hello3", "a_i", "5", "a_f", "6", "subject", "blah blah blah 5") + .add(id, "6", "a_s", "hello4", "a_i", "6", "a_f", "7", "subject", "blah blah blah 6") + .add(id, "7", "a_s", "hello3", "a_i", "7", "a_f", "8", "subject", "blah blah blah 7") + .add(id, "8", "a_s", "hello3", "a_i", "8", "a_f", "9", "subject", "blah blah blah 8") + .add(id, "9", "a_s", "hello0", "a_i", "9", "a_f", "10", "subject", "blah blah blah 9") + .commit(cluster.getSolrClient(), COLLECTIONORALIAS); + + TupleStream stream; + List tuples; + + StreamFactory factory = new StreamFactory() + .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress()) + .withFunctionName("search", CloudSolrStream.class) + .withFunctionName("having", HavingStream.class) + .withFunctionName("and", AndOperation.class) + .withFunctionName("or", OrOperation.class) + .withFunctionName("not", NotOperation.class) + .withFunctionName("gt", GreaterThanOperation.class) + .withFunctionName("lt", LessThanOperation.class) + .withFunctionName("eq", EqualsOperation.class) + .withFunctionName("lteq", LessThanEqualToOperation.class) + .withFunctionName("gteq", GreaterThanEqualToOperation.class) + .withFunctionName("parallel", ParallelStream.class); + + stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), eq(a_i, 9)))"); + StreamContext context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 1); + Tuple t = tuples.get(0); + assertTrue(t.getString("id").equals("9")); + + stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), and(eq(a_i, 9),lt(a_i, 10))))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 1); + t = tuples.get(0); + assertTrue(t.getString("id").equals("9")); + + stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\",having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), or(eq(a_i, 9),eq(a_i, 8))))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 2); + t = tuples.get(0); + assertTrue(t.getString("id").equals("8")); + + t = tuples.get(1); + assertTrue(t.getString("id").equals("9")); + + + stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\", having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), and(eq(a_i, 9),not(eq(a_i, 9)))))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + assert(tuples.size() == 0); + + + stream = factory.constructStream("parallel(" + COLLECTIONORALIAS + ", workers=2, sort=\"a_f asc\",having(search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\", partitionKeys=id), and(lteq(a_i, 9), gteq(a_i, 8))))"); + context = new StreamContext(); + context.setSolrClientCache(solrClientCache); + stream.setStreamContext(context); + tuples = getTuples(stream); + + System.out.println("####Tuples:"+tuples.size()); + assert(tuples.size() == 2); + + t = tuples.get(0); + assertTrue(t.getString("id").equals("8")); + + t = tuples.get(1); + assertTrue(t.getString("id").equals("9")); + + solrClientCache.close(); + } + @Test public void testFetchStream() throws Exception {