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/01/21 19:06:50 UTC

[lucene-solr] branch branch_8x updated (440e6ea -> d837877)

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

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


    from 440e6ea  LUCENE-8649: LatLonShape's within and disjoint queries can return false positives with indexed multi-shapes
     new 6395f0d  SOLR-131476: Add movingMAD Stream Evaluator
     new d837877  SOLR-131476: Add double value to test vector

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/solr/client/solrj/io/Lang.java  |  1 +
 ...MedianEvaluator.java => MovingMADEvaluator.java} | 15 +++++++++------
 .../org/apache/solr/client/solrj/io/TestLang.java   |  2 +-
 .../client/solrj/io/stream/MathExpressionTest.java  | 21 +++++++++++++++++++++
 4 files changed, 32 insertions(+), 7 deletions(-)
 copy solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/{MovingMedianEvaluator.java => MovingMADEvaluator.java} (85%)


[lucene-solr] 02/02: SOLR-131476: Add double value to test vector

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d837877e78c9cb66835099ac31eaea68b732ebc4
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Mon Jan 21 14:01:13 2019 -0500

    SOLR-131476: Add double value to test vector
---
 .../org/apache/solr/client/solrj/io/stream/MathExpressionTest.java   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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 7102987..d6143f3 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
@@ -4315,7 +4315,7 @@ public class MathExpressionTest extends SolrCloudTestCase {
 
   @Test
   public void testMovingMAD() throws Exception {
-    String cexpr = "movingMAD(array(1,2,3,4,5,6,9), 4)";
+    String cexpr = "movingMAD(array(1,2,3,4,5,6,9.25), 4)";
     ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
     paramsLoc.set("expr", cexpr);
     paramsLoc.set("qt", "/stream");
@@ -4327,10 +4327,11 @@ public class MathExpressionTest extends SolrCloudTestCase {
     assertTrue(tuples.size() == 1);
     List<Number> out = (List<Number>)tuples.get(0).get("return-value");
     assertTrue(out.size()==4);
+    System.out.println("MAD:"+out);
     assertEquals((double) out.get(0).doubleValue(), 1, .0);
     assertEquals((double) out.get(1).doubleValue(), 1, .0);
     assertEquals((double) out.get(2).doubleValue(), 1, .0);
-    assertEquals((double) out.get(3).doubleValue(), 1.5, .0);
+    assertEquals((double) out.get(3).doubleValue(), 1.59375, .0);
   }
 
   @Test


[lucene-solr] 01/02: SOLR-131476: Add movingMAD Stream Evaluator

Posted by jb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6395f0d543d35d0a903ed63877bb535bbd7eaf9a
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Mon Jan 21 13:45:57 2019 -0500

    SOLR-131476: Add movingMAD Stream Evaluator
---
 .../java/org/apache/solr/client/solrj/io/Lang.java |  1 +
 .../client/solrj/io/eval/MovingMADEvaluator.java   | 71 ++++++++++++++++++++++
 .../org/apache/solr/client/solrj/io/TestLang.java  |  2 +-
 .../client/solrj/io/stream/MathExpressionTest.java | 20 ++++++
 4 files changed, 93 insertions(+), 1 deletion(-)

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 9229dcf..455576c 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
@@ -281,6 +281,7 @@ public class Lang {
         .withFunctionName("rtrim", RightShiftEvaluator.class)
         .withFunctionName("repeat", RepeatEvaluator.class)
         .withFunctionName("natural", NaturalEvaluator.class)
+        .withFunctionName("movingMAD", MovingMADEvaluator.class)
 
         // Boolean Stream Evaluators
 
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/MovingMADEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/MovingMADEvaluator.java
new file mode 100644
index 0000000..6bbe8ba
--- /dev/null
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/MovingMADEvaluator.java
@@ -0,0 +1,71 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+
+public class MovingMADEvaluator extends RecursiveNumericEvaluator implements TwoValueWorker {
+  protected static final long serialVersionUID = 1L;
+
+  public MovingMADEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
+    super(expression, factory);
+  }
+
+  @Override
+  public Object doWork(Object first, Object second) throws IOException{
+    if(null == first){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
+    }
+    if(null == second){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
+    }
+    if(!(first instanceof List<?>)){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the first value, expecting a List",toExpression(constructingFactory), first.getClass().getSimpleName()));
+    }
+    if(!(second instanceof Number)){
+      throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - found type %s for the second value, expecting a Number",toExpression(constructingFactory), first.getClass().getSimpleName()));
+    }
+
+    List<?> values = (List<?>)first;
+    int window = ((Number)second).intValue();
+
+    List<Number> moving = new ArrayList<>();
+    DescriptiveStatistics slider = new DescriptiveStatistics(window);
+    for(Object value : values){
+      slider.addValue(((Number)value).doubleValue());
+      if(slider.getN() >= window){
+        double[] doubles = slider.getValues();
+        double mean = slider.getMean();
+        double total = 0;
+        for(double d : doubles) {
+          total+=Math.abs(d-mean);
+        }
+        moving.add(total/window);
+      }
+    }
+
+    return moving;
+  }
+
+}
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 2632e14..040a1d9 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
@@ -74,7 +74,7 @@ public class TestLang extends LuceneTestCase {
       "convexHull", "getVertices", "getBaryCenter", "getArea", "getBoundarySize","oscillate",
       "getAmplitude", "getPhase", "getAngularFrequency", "enclosingDisk", "getCenter", "getRadius",
       "getSupportPoints", "pairSort", "log10", "plist", "recip", "pivot", "ltrim", "rtrim", "export",
-      "zplot", "natural", "repeat"};
+      "zplot", "natural", "repeat", "movingMAD"};
 
   @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 45698d9..7102987 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
@@ -4314,6 +4314,26 @@ public class MathExpressionTest extends SolrCloudTestCase {
   }
 
   @Test
+  public void testMovingMAD() throws Exception {
+    String cexpr = "movingMAD(array(1,2,3,4,5,6,9), 4)";
+    ModifiableSolrParams paramsLoc = new ModifiableSolrParams();
+    paramsLoc.set("expr", cexpr);
+    paramsLoc.set("qt", "/stream");
+    String url = cluster.getJettySolrRunners().get(0).getBaseUrl().toString()+"/"+COLLECTIONORALIAS;
+    TupleStream solrStream = new SolrStream(url, paramsLoc);
+    StreamContext context = new StreamContext();
+    solrStream.setStreamContext(context);
+    List<Tuple> tuples = getTuples(solrStream);
+    assertTrue(tuples.size() == 1);
+    List<Number> out = (List<Number>)tuples.get(0).get("return-value");
+    assertTrue(out.size()==4);
+    assertEquals((double) out.get(0).doubleValue(), 1, .0);
+    assertEquals((double) out.get(1).doubleValue(), 1, .0);
+    assertEquals((double) out.get(2).doubleValue(), 1, .0);
+    assertEquals((double) out.get(3).doubleValue(), 1.5, .0);
+  }
+
+  @Test
   public void testMannWhitney() throws Exception {
     String cexpr = "mannWhitney(array(0.15,0.10,0.11,0.24,0.08,0.08,0.10,0.10,0.10,0.12,0.04,0.07), " +
                                "array(0.10,0.20,0.30,0.10,0.10,0.02,0.05,0.07))";