Apache Solr open-source search software
SOLR-10802: Fix problem with variable assignment
Joel Bernsteinebd130b7e272
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/PlotStream.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/PlotStream.javaindex b652de977ee..c893240e1d1 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/PlotStream.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/PlotStream.java@@ -155,21 +155,31 @@ public class PlotStream extends TupleStream implements Expressible {finished = true;Map<String, Object> values = new HashMap<>();- String plot= stringParams.get("type");- StreamEvaluator xvalues = evaluatorParams.get("x");- StreamEvaluator yvalues = evaluatorParams.get("y");+ // add all string based params+ // these could come from the context, or they will just be treated as straight strings+ for(Entry<String,String> param : stringParams.entrySet()){+ if(streamContext.getLets().containsKey(param.getValue())){+ values.put(param.getKey(), streamContext.getLets().get(param.getValue()));+ }+ else{+ values.put(param.getKey(), param.getValue());+ }+ }++ // add all evaluators+ for(Entry<String,StreamEvaluator> param : evaluatorParams.entrySet()){+ values.put(param.getKey(), param.getValue().evaluateOverContext());+ }- List<Number> y = (List<Number>)yvalues.evaluateOverContext();- List<Number> x = null;+ List<Number> y = (List<Number>)values.get("y");+ List<Number> x = (List<Number>)values.get("x");- if(xvalues == null) {+ if(x == null) {//x is null so add a sequencex = new ArrayList();for(int i=0; i<y.size(); i++) {x.add(i+1);}- } else {- x = (List<Number>) xvalues.evaluateOverContext();}List<List<Number>> xy = new ArrayList();@@ -180,7 +190,7 @@ public class PlotStream extends TupleStream implements Expressible {xy.add(pair);}- values.put("plot", plot);+ values.put("plot", values.get("type"));values.put("data", xy);Tuple tup = new Tuple(values);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.javaindex d749ede9471..6bf320c7779 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@@ -6065,7 +6065,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {@Testpublic void testPlot() throws Exception {- String cexpr = "plot(type=scatter, x=array(1,2,3), y=array(5,6,3))";+ String cexpr = "let(a=array(3,2,3), plot(type=scatter, x=a, y=array(5,6,3)))";ModifiableSolrParams paramsLoc = new ModifiableSolrParams();paramsLoc.set("expr", cexpr);paramsLoc.set("qt", "/stream");@@ -6080,7 +6080,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {List<List<Number>> data = (List<List<Number>>)tuples.get(0).get("data");assertTrue(data.size() == 3);List<Number> pair1 = data.get(0);- assertTrue(pair1.get(0).intValue() == 1);+ assertTrue(pair1.get(0).intValue() == 3);assertTrue(pair1.get(1).intValue() == 5);List<Number> pair2 = data.get(1);assertTrue(pair2.get(0).intValue() == 2);