lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject lucene-solr:master: SOLR-8530: Add support for single quoted aggregate HAVING comparisons
Date Wed, 04 Jan 2017 02:07:13 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master db7d2ff16 -> ccdbb6ac0


SOLR-8530: Add support for single quoted aggregate HAVING comparisons


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

Branch: refs/heads/master
Commit: ccdbb6ac0e0094985e5145c84b3cc2814ababf1d
Parents: db7d2ff
Author: Joel Bernstein <jbernste@apache.org>
Authored: Tue Jan 3 20:27:22 2017 -0500
Committer: Joel Bernstein <jbernste@apache.org>
Committed: Tue Jan 3 20:27:22 2017 -0500

----------------------------------------------------------------------
 .../client/solrj/io/ops/EqualsOperation.java    |  2 +-
 .../io/ops/GreaterThanEqualToOperation.java     |  2 +-
 .../solrj/io/ops/GreaterThanOperation.java      |  2 +-
 .../solr/client/solrj/io/ops/LeafOperation.java |  9 ++++++
 .../solrj/io/ops/LessThanEqualToOperation.java  |  2 +-
 .../client/solrj/io/ops/LessThanOperation.java  |  2 +-
 .../solrj/io/stream/StreamExpressionTest.java   | 31 ++++++++++++++++++--
 7 files changed, 43 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/EqualsOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/EqualsOperation.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/EqualsOperation.java
index 1958551..8506f30 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/EqualsOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/EqualsOperation.java
@@ -54,7 +54,7 @@ public class EqualsOperation extends LeafOperation {
 
   public StreamExpression toExpression(StreamFactory factory) throws IOException {
     StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-    expression.addParameter(field);
+    expression.addParameter(quote(field));
     expression.addParameter(Double.toString(val));
     return expression;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanEqualToOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanEqualToOperation.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanEqualToOperation.java
index 87c8364..5e6dd85 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanEqualToOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanEqualToOperation.java
@@ -54,7 +54,7 @@ public class GreaterThanEqualToOperation extends LeafOperation {
 
   public StreamExpression toExpression(StreamFactory factory) throws IOException {
     StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-    expression.addParameter(field);
+    expression.addParameter(quote(field));
     expression.addParameter(Double.toString(val));
     return expression;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanOperation.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanOperation.java
index 664438a..9c181c1 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/GreaterThanOperation.java
@@ -54,7 +54,7 @@ public class GreaterThanOperation extends LeafOperation {
 
   public StreamExpression toExpression(StreamFactory factory) throws IOException {
     StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-    expression.addParameter(field);
+    expression.addParameter(quote(field));
     expression.addParameter(Double.toString(val));
     return expression;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LeafOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LeafOperation.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LeafOperation.java
index b6ad897..9a5c407 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LeafOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LeafOperation.java
@@ -45,6 +45,7 @@ public abstract class LeafOperation implements BooleanOperation {
 
   public LeafOperation(StreamExpression expression, StreamFactory factory) throws IOException
{
     this.field = factory.getValueOperand(expression, 0);
+    this.field = this.field.replace("'","");
     this.val = Double.parseDouble(factory.getValueOperand(expression, 1));
   }
 
@@ -56,4 +57,12 @@ public abstract class LeafOperation implements BooleanOperation {
         .withImplementingClass(getClass().getName())
         .withExpression(toExpression(factory).toString());
   }
+
+  protected String quote(String s) {
+    if(s.contains("(")) {
+      return "'"+s+"'";
+    }
+
+    return s;
+  }
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanEqualToOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanEqualToOperation.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanEqualToOperation.java
index 2da3274..ca362cf 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanEqualToOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanEqualToOperation.java
@@ -54,7 +54,7 @@ public class LessThanEqualToOperation extends LeafOperation {
 
   public StreamExpression toExpression(StreamFactory factory) throws IOException {
     StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-    expression.addParameter(field);
+    expression.addParameter(quote(field));
     expression.addParameter(Double.toString(val));
     return expression;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanOperation.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanOperation.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanOperation.java
index c1cec95..433f45f 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanOperation.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/ops/LessThanOperation.java
@@ -54,7 +54,7 @@ public class LessThanOperation extends LeafOperation {
 
   public StreamExpression toExpression(StreamFactory factory) throws IOException {
     StreamExpression expression = new StreamExpression(factory.getFunctionName(this.getClass()));
-    expression.addParameter(field);
+    expression.addParameter(quote(field));
     expression.addParameter(Double.toString(val));
     return expression;
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ccdbb6ac/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 fd088f1..83c093c 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
@@ -837,6 +837,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
         .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
         .withFunctionName("search", CloudSolrStream.class)
         .withFunctionName("having", HavingStream.class)
+        .withFunctionName("rollup", RollupStream.class)
+        .withFunctionName("sum", SumMetric.class)
         .withFunctionName("and", AndOperation.class)
         .withFunctionName("or", OrOperation.class)
         .withFunctionName("not", NotOperation.class)
@@ -895,7 +897,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {
     stream.setStreamContext(context);
     tuples = getTuples(stream);
 
-    System.out.println("####Tuples:"+tuples.size());
     assert(tuples.size() == 2);
 
     t = tuples.get(0);
@@ -904,6 +905,18 @@ public class StreamExpressionTest extends SolrCloudTestCase {
     t = tuples.get(1);
     assertTrue(t.getString("id").equals("9"));
 
+
+    stream = factory.constructStream("having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS
+ ", q=*:*, fl=\"id,a_s,a_i,a_f\", sort=\"a_f asc\")), eq('sum(a_i)', 9))");
+    context = new StreamContext();
+    context.setSolrClientCache(solrClientCache);
+    stream.setStreamContext(context);
+    tuples = getTuples(stream);
+
+    assert(tuples.size() == 1);
+
+    t = tuples.get(0);
+    assertTrue(t.getDouble("a_f") == 10.0D);
+
     solrClientCache.close();
   }
 
@@ -933,6 +946,8 @@ public class StreamExpressionTest extends SolrCloudTestCase {
         .withCollectionZkHost(COLLECTIONORALIAS, cluster.getZkServer().getZkAddress())
         .withFunctionName("search", CloudSolrStream.class)
         .withFunctionName("having", HavingStream.class)
+        .withFunctionName("rollup", RollupStream.class)
+        .withFunctionName("sum", SumMetric.class)
         .withFunctionName("and", AndOperation.class)
         .withFunctionName("or", OrOperation.class)
         .withFunctionName("not", NotOperation.class)
@@ -992,7 +1007,6 @@ public class StreamExpressionTest extends SolrCloudTestCase {
     stream.setStreamContext(context);
     tuples = getTuples(stream);
 
-    System.out.println("####Tuples:"+tuples.size());
     assert(tuples.size() == 2);
 
     t = tuples.get(0);
@@ -1001,6 +1015,19 @@ public class StreamExpressionTest extends SolrCloudTestCase {
     t = tuples.get(1);
     assertTrue(t.getString("id").equals("9"));
 
+    stream = factory.constructStream("parallel("+COLLECTIONORALIAS+", workers=2, sort=\"a_f
asc\", having(rollup(over=a_f, sum(a_i), search(" + COLLECTIONORALIAS + ", q=*:*, fl=\"id,a_s,a_i,a_f\",
sort=\"a_f asc\", partitionKeys=a_f)), eq('sum(a_i)', 9)))");
+    context = new StreamContext();
+    context.setSolrClientCache(solrClientCache);
+    stream.setStreamContext(context);
+    tuples = getTuples(stream);
+
+    assert(tuples.size() == 1);
+
+    t = tuples.get(0);
+    assertTrue(t.getDouble("a_f") == 10.0D);
+
+
+
     solrClientCache.close();
   }
 


Mime
View raw message