SOLR-10802: Fix problem with variable assignment

This commit is contained in:
Joel Bernstein 2017-07-14 11:07:08 -04:00
parent 3df97d3f0c
commit ebd130b7e2
2 changed files with 21 additions and 11 deletions

View File

@ -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());
}
}
List<Number> y = (List<Number>)yvalues.evaluateOverContext();
List<Number> x = null;
// add all evaluators
for(Entry<String,StreamEvaluator> param : evaluatorParams.entrySet()){
values.put(param.getKey(), param.getValue().evaluateOverContext());
}
if(xvalues == null) {
List<Number> y = (List<Number>)values.get("y");
List<Number> x = (List<Number>)values.get("x");
if(x == null) {
//x is null so add a sequence
x = 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);

View File

@ -6065,7 +6065,7 @@ public class StreamExpressionTest extends SolrCloudTestCase {
@Test
public 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);