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/14 21:49:35 UTC

[lucene-solr] branch master updated: SOLR-13550: Allow zplot to automatically create the x axis

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 0038e93  SOLR-13550: Allow zplot to automatically create the x axis
0038e93 is described below

commit 0038e936671fa7798360ff09c02d4d33c6907eb8
Author: Joel Bernstein <jb...@apache.org>
AuthorDate: Fri Jun 14 17:49:03 2019 -0400

    SOLR-13550: Allow zplot to automatically create the x axis
---
 .../solr/client/solrj/io/stream/ZplotStream.java   |  9 ++++++
 .../client/solrj/io/stream/MathExpressionTest.java | 32 ++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ZplotStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ZplotStream.java
index e7138cb..dd93455 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ZplotStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/ZplotStream.java
@@ -192,6 +192,15 @@ public class ZplotStream extends TupleStream implements Expressible {
 
         outTuples.add(tuple);
       }
+
+      //Generate the x axis if the tuples contain y and not x
+      if(outTuples.get(0).fields.containsKey("y") && !outTuples.get(0).fields.containsKey("x")) {
+        int x = 0;
+        for(Tuple tuple : outTuples) {
+          tuple.put("x", x++);
+        }
+      }
+
     } else if(distribution) {
       Object o = evaluated.get("dist");
       if(o instanceof RealDistribution) {
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 f38b90e..e739866 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
@@ -1473,6 +1473,38 @@ public class MathExpressionTest extends SolrCloudTestCase {
     assertEquals(out.getDouble("x").doubleValue(), 4.0, 0.0);
     assertEquals(out.getDouble("y").doubleValue(), 13.0, 0.0);
 
+
+    cexpr = "let(b=array(10,11,12,13),"+
+        "        zplot(y=b))";
+
+    paramsLoc = new ModifiableSolrParams();
+    paramsLoc.set("expr", cexpr);
+    paramsLoc.set("qt", "/stream");
+    solrStream = new SolrStream(url, paramsLoc);
+    context = new StreamContext();
+    solrStream.setStreamContext(context);
+    tuples = getTuples(solrStream);
+    assertTrue(tuples.size() == 4);
+    out = tuples.get(0);
+
+    assertEquals(out.getDouble("x").doubleValue(), 0.0, 0.0);
+    assertEquals(out.getDouble("y").doubleValue(), 10.0, 0.0);
+
+    out = tuples.get(1);
+
+    assertEquals(out.getDouble("x").doubleValue(), 1.0, 0.0);
+    assertEquals(out.getDouble("y").doubleValue(), 11.0, 0.0);
+
+    out = tuples.get(2);
+
+    assertEquals(out.getDouble("x").doubleValue(), 2.0, 0.0);
+    assertEquals(out.getDouble("y").doubleValue(), 12.0, 0.0);
+
+    out = tuples.get(3);
+
+    assertEquals(out.getDouble("x").doubleValue(), 3.0, 0.0);
+    assertEquals(out.getDouble("y").doubleValue(), 13.0, 0.0);
+
     cexpr = "zplot(dist=binomialDistribution(10, .50))";
 
     paramsLoc = new ModifiableSolrParams();