You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2019/06/15 17:54:50 UTC

[lucene-solr] branch master updated: SOLR-13552: Add recNum Stream Evaluator

This is an automated email from the ASF dual-hosted git repository.

jbernste pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 03e7205  SOLR-13552: Add recNum Stream Evaluator
03e7205 is described below

commit 03e7205c89598c0f96168601ea732457b3af42f6
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Sat Jun 15 13:54:37 2019 -0400

    SOLR-13552: Add recNum Stream Evaluator
---
 .../java/org/apache/solr/client/solrj/io/Lang.java |  1 +
 .../solr/client/solrj/io/eval/RecNumEvaluator.java | 55 ++++++++++++++++++++++
 .../org/apache/solr/client/solrj/io/TestLang.java  |  2 +-
 .../client/solrj/io/stream/MathExpressionTest.java |  6 ++-
 4 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
index 5b499b4..4a1051e 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/Lang.java
@@ -286,6 +286,7 @@ public class Lang {
         .withFunctionName("repeat", RepeatEvaluator.class)
         .withFunctionName("natural", NaturalEvaluator.class)
         .withFunctionName("movingMAD", MovingMADEvaluator.class)
+        .withFunctionName("recNum", RecNumEvaluator.class)
 
         // Boolean Stream Evaluators
 
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecNumEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecNumEvaluator.java
new file mode 100644
index 0000000..bd17dbd
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecNumEvaluator.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.client.solrj.io.eval;
+
+import java.io.IOException;
+
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.stream.expr.Explanation;
+import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+public class RecNumEvaluator extends SourceEvaluator {
+  private static final long serialVersionUID = 1L;
+
+  private int index = -1;
+
+  public RecNumEvaluator(StreamExpression expression, StreamFactory factory) {
+
+  }
+
+  @Override
+  public Object evaluate(Tuple tuple) throws IOException {
+    return ++index;
+  }
+
+  @Override
+  public StreamExpressionParameter toExpression(StreamFactory factory) throws IOException {
+    return new StreamExpression(factory.getFunctionName(getClass()));
+  }
+
+  @Override
+  public Explanation toExplanation(StreamFactory factory) throws IOException {
+    return new Explanation(nodeId.toString())
+        .withExpressionType(ExpressionType.EVALUATOR)
+        .withImplementingClass(getClass().getName())
+        .withExpression(toExpression(factory).toString());
+  }
+
+}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
index 5894c1b..b7db83d 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/TestLang.java
@@ -75,7 +75,7 @@ public class TestLang extends SolrTestCase {
       "convexHull", "getVertices", "getBaryCenter", "getArea", "getBoundarySize","oscillate",
       "getAmplitude", "getPhase", "getAngularFrequency", "enclosingDisk", "getCenter", "getRadius",
       "getSupportPoints", "pairSort", "log10", "plist", "recip", "pivot", "ltrim", "rtrim", "export",
-      "zplot", "natural", "repeat", "movingMAD", "hashRollup", "noop", "var", "stddev"};
+      "zplot", "natural", "repeat", "movingMAD", "hashRollup", "noop", "var", "stddev", "recNum"};
 
   @Test
   public void testLang() {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
index e739866..c14e126 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
@@ -1974,7 +1974,8 @@ public class MathExpressionTest extends SolrCloudTestCase {
   public void testSelectWithSequentialEvaluators() throws Exception {
     String cexpr = "select(list(tuple(a=add(1,2)), tuple(a=add(2,2))), " +
         "                  add(1, a) as blah, " +
-        "                  add(1, blah) as blah1)";
+        "                  add(1, blah) as blah1," +
+        "                  recNum() as recNum)";
     ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
     paramsLoc.set("expr", cexpr);
     paramsLoc.set("qt", "/stream");
@@ -1987,10 +1988,13 @@ public class MathExpressionTest extends SolrCloudTestCase {
     Tuple tuple0 = tuples.get(0);
     assertEquals(tuple0.getLong("blah").longValue(), 4L);
     assertEquals(tuple0.getLong("blah1").longValue(), 5L);
+    assertEquals(tuple0.getLong("recNum").longValue(), 0);
 
     Tuple tuple1 = tuples.get(1);
     assertEquals(tuple1.getLong("blah").longValue(), 5L);
     assertEquals(tuple1.getLong("blah1").longValue(), 6L);
+    assertEquals(tuple1.getLong("recNum").longValue(), 1);
+
   }
 
   @Test