lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [06/18] lucene-solr:jira/solr-11702: SOLR-11799: Fix NPE and class cast exceptions in the TimeSeriesStream
Date Wed, 03 Jan 2018 10:51:54 GMT
SOLR-11799: Fix NPE and class cast exceptions in the TimeSeriesStream


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0c4fb312
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0c4fb312
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0c4fb312

Branch: refs/heads/jira/solr-11702
Commit: 0c4fb31205aa68e4d432ce3a67f5cac6bb5a9681
Parents: 152d223
Author: Joel Bernstein <jbernste@apache.org>
Authored: Thu Dec 28 11:14:31 2017 -0500
Committer: Joel Bernstein <jbernste@apache.org>
Committed: Thu Dec 28 11:14:31 2017 -0500

----------------------------------------------------------------------
 .../solrj/io/stream/TimeSeriesStream.java       | 12 +++---
 .../solrj/io/stream/StreamExpressionTest.java   | 45 ++++++++++++++++++++
 2 files changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0c4fb312/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
index 12b04de..3c2c2b5 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/stream/TimeSeriesStream.java
@@ -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 {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0c4fb312/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
----------------------------------------------------------------------
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.java
index c564700..bc3dee5 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
@@ -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


Mime
View raw message