mirror of https://github.com/apache/lucene.git
SOLR-11799: Fix NPE and class cast exceptions in the TimeSeriesStream
This commit is contained in:
parent
152d223b32
commit
0c4fb31205
|
@ -389,11 +389,13 @@ public class TimeSeriesStream extends TupleStream implements Expressible {
|
|||
for(Metric metric : _metrics) {
|
||||
String identifier = metric.getIdentifier();
|
||||
if(!identifier.startsWith("count(")) {
|
||||
double d = (double)bucket.get("facet_"+m);
|
||||
if(metric.outputLong) {
|
||||
t.put(identifier, Math.round(d));
|
||||
} else {
|
||||
t.put(identifier, d);
|
||||
if(bucket.get("facet_"+m) != null) {
|
||||
Number d = (Number) bucket.get("facet_" + m);
|
||||
if (metric.outputLong) {
|
||||
t.put(identifier, Math.round(d.doubleValue()));
|
||||
} else {
|
||||
t.put(identifier, d.doubleValue());
|
||||
}
|
||||
}
|
||||
++m;
|
||||
} else {
|
||||
|
|
|
@ -5493,6 +5493,51 @@ public class StreamExpressionTest extends SolrCloudTestCase {
|
|||
assertTrue(tuples.get(3).getDouble("max(price_f)").equals(400D));
|
||||
assertTrue(tuples.get(3).getDouble("min(price_f)").equals(400D));
|
||||
|
||||
|
||||
expr = "timeseries("+COLLECTIONORALIAS+", q=\"*:*\", start=\"2012-01-01T01:00:00.000Z\", " +
|
||||
"end=\"2016-12-01T01:00:00.000Z\", " +
|
||||
"gap=\"+1YEAR\", " +
|
||||
"field=\"test_dt\", " +
|
||||
"format=\"yyyy-MM\", " +
|
||||
"count(*), sum(price_f), max(price_f), min(price_f))";
|
||||
paramsLoc = new ModifiableSolrParams();
|
||||
paramsLoc.set("expr", expr);
|
||||
paramsLoc.set("qt", "/stream");
|
||||
|
||||
solrStream = new SolrStream(url, paramsLoc);
|
||||
|
||||
solrStream.setStreamContext(context);
|
||||
tuples = getTuples(solrStream);
|
||||
assertTrue(tuples.size() == 5);
|
||||
assertTrue(tuples.get(0).get("test_dt").equals("2012-01"));
|
||||
assertTrue(tuples.get(0).getLong("count(*)").equals(0L));
|
||||
assertTrue(tuples.get(0).getDouble("sum(price_f)") == null);
|
||||
assertTrue(tuples.get(0).getDouble("max(price_f)") == null);
|
||||
assertTrue(tuples.get(0).getDouble("min(price_f)") == null);
|
||||
|
||||
assertTrue(tuples.get(1).get("test_dt").equals("2013-01"));
|
||||
assertTrue(tuples.get(1).getLong("count(*)").equals(100L));
|
||||
assertTrue(tuples.get(1).getDouble("sum(price_f)").equals(10000D));
|
||||
assertTrue(tuples.get(1).getDouble("max(price_f)").equals(100D));
|
||||
assertTrue(tuples.get(1).getDouble("min(price_f)").equals(100D));
|
||||
|
||||
assertTrue(tuples.get(2).get("test_dt").equals("2014-01"));
|
||||
assertTrue(tuples.get(2).getLong("count(*)").equals(50L));
|
||||
assertTrue(tuples.get(2).getDouble("sum(price_f)").equals(25000D));
|
||||
assertTrue(tuples.get(2).getDouble("max(price_f)").equals(500D));
|
||||
assertTrue(tuples.get(2).getDouble("min(price_f)").equals(500D));
|
||||
|
||||
assertTrue(tuples.get(3).get("test_dt").equals("2015-01"));
|
||||
assertTrue(tuples.get(3).getLong("count(*)").equals(50L));
|
||||
assertTrue(tuples.get(3).getDouble("sum(price_f)").equals(15000D));
|
||||
assertTrue(tuples.get(3).getDouble("max(price_f)").equals(300D));
|
||||
assertTrue(tuples.get(3).getDouble("min(price_f)").equals(300D));
|
||||
|
||||
assertTrue(tuples.get(4).get("test_dt").equals("2016-01"));
|
||||
assertTrue(tuples.get(4).getLong("count(*)").equals(50L));
|
||||
assertTrue(tuples.get(4).getDouble("sum(price_f)").equals(20000D));
|
||||
assertTrue(tuples.get(4).getDouble("max(price_f)").equals(400D));
|
||||
assertTrue(tuples.get(4).getDouble("min(price_f)").equals(400D));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue