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/12/10 18:13:33 UTC
[lucene-solr] branch master updated: SOLR-14043: Allow the
precision Stream Evaluator to operate on matrices
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 8c6a264 SOLR-14043: Allow the precision Stream Evaluator to operate on matrices
8c6a264 is described below
commit 8c6a2640ed3cffacb7f4cb5a7aa71ec06f5d44f2
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Tue Dec 10 12:57:05 2019 -0500
SOLR-14043: Allow the precision Stream Evaluator to operate on matrices
---
.../client/solrj/io/eval/PrecisionEvaluator.java | 13 ++++++++++-
.../client/solrj/io/stream/MathExpressionTest.java | 26 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PrecisionEvaluator.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PrecisionEvaluator.java
index 532f2ea..09df083 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PrecisionEvaluator.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/PrecisionEvaluator.java
@@ -25,7 +25,7 @@ import org.apache.commons.math3.util.Precision;
import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
-public class PrecisionEvaluator extends RecursiveNumericEvaluator implements TwoValueWorker {
+public class PrecisionEvaluator extends RecursiveObjectEvaluator implements TwoValueWorker {
protected static final long serialVersionUID = 1L;
public PrecisionEvaluator(StreamExpression expression, StreamFactory factory) throws IOException{
@@ -43,6 +43,17 @@ public class PrecisionEvaluator extends RecursiveNumericEvaluator implements Two
}
else if(value instanceof List){
return ((List<?>)value).stream().map(innerValue -> doWork(innerValue, ((Number)value2).intValue())).collect(Collectors.toList());
+ } else if(value instanceof Matrix) {
+ int p = ((Number)value2).intValue();
+ Matrix matrix = (Matrix)value;
+ double[][] data = matrix.getData();
+ for(int i=0; i<data.length; ++i) {
+ for(int j=0; j < data[i].length; j++) {
+ data[i][j] = Precision.round(data[i][j], p);
+ }
+ }
+
+ return matrix;
}
else{
return Precision.round(((Number)value).doubleValue(), ((Number)value2).intValue());
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 ae7eb68..25de9e1 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
@@ -5464,6 +5464,32 @@ public class MathExpressionTest extends SolrCloudTestCase {
}
@Test
+ public void testPrecisionMatrix() throws Exception {
+ String cexpr = "let(a=matrix(array(1.3333999, 2.4444445), array(2.333333, 10.10009)), b=precision(a, 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<List<Number>> rows = (List<List<Number>>)tuples.get(0).get("b");
+ assertTrue(rows.size() == 2);
+ List<Number> row1 = rows.get(0);
+ assertTrue(row1.size() == 2);
+ assertEquals(row1.get(0).doubleValue(), 1.3334, 0);
+ assertEquals(row1.get(1).doubleValue(), 2.4444, 0);
+
+ List<Number> row2 = rows.get(1);
+ assertTrue(row2.size() == 2);
+ assertEquals(row2.get(0).doubleValue(), 2.3333, 0);
+ assertEquals(row2.get(1).doubleValue(), 10.1001, 0);
+ }
+
+ @Test
public void testMinMaxScale() throws Exception {
String cexpr = "let(echo=true, a=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50))), " +
"b=minMaxScale(matrix(array(1,2,3,4,5), array(10,20,30,40,50)), 0, 100)," +