You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2021/08/22 21:45:37 UTC

[incubator-streampipes] 02/02: [STREAMPIPES-410] Fix auto-aggregation exception in case of empty results

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 67a6e753bdcdde923360718b8026b3189ed24858
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Sun Aug 22 23:45:24 2021 +0200

    [STREAMPIPES-410] Fix auto-aggregation exception in case of empty results
---
 .../dataexplorer/v4/AutoAggregationHandler.java    | 40 ++++++++++++----------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/AutoAggregationHandler.java b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/AutoAggregationHandler.java
index 6a69dae..ff231cf 100644
--- a/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/AutoAggregationHandler.java
+++ b/streampipes-data-explorer/src/main/java/org/apache/streampipes/dataexplorer/v4/AutoAggregationHandler.java
@@ -49,24 +49,28 @@ public class AutoAggregationHandler {
   public ProvidedQueryParams makeAutoAggregationQueryParams() throws IllegalArgumentException {
     checkAllArgumentsPresent();
     try {
-    DataResult newest = getSingleRecord(Order.DESC);
-    DataResult oldest = getSingleRecord(Order.ASC);
-    String sampleField = getSampleField(newest);
-    Integer count = getCount(sampleField);
-    if (count <= MAX_RETURN_LIMIT) {
-      LOG.debug("Auto-Aggregation disabled as {} results <= max return limit {}", count, MAX_RETURN_LIMIT);
-      return disableAutoAgg(this.queryParams);
-    } else {
-      LOG.debug("Performing auto-aggregation");
-
-        int aggValue = getAggregationValue(newest, oldest);
-        LOG.debug("Setting auto-aggregation value to {} ms", aggValue);
-        queryParams.update(QP_TIME_INTERVAL, aggValue + "ms");
-      return disableAutoAgg(queryParams);
-    }
-    } catch (ParseException e) {
-      e.printStackTrace();
-    }
+      DataResult newest = getSingleRecord(Order.DESC);
+      DataResult oldest = getSingleRecord(Order.ASC);
+      if (newest.getTotal() > 0) {
+        String sampleField = getSampleField(newest);
+        Integer count = getCount(sampleField);
+        if (count <= MAX_RETURN_LIMIT) {
+          LOG.debug("Auto-Aggregation disabled as {} results <= max return limit {}", count, MAX_RETURN_LIMIT);
+          return disableAutoAgg(this.queryParams);
+        } else {
+          LOG.debug("Performing auto-aggregation");
+
+          int aggValue = getAggregationValue(newest, oldest);
+          LOG.debug("Setting auto-aggregation value to {} ms", aggValue);
+          queryParams.update(QP_TIME_INTERVAL, aggValue + "ms");
+          return disableAutoAgg(queryParams);
+        }
+      } else {
+        return disableAutoAgg(this.queryParams);
+      }
+      } catch(ParseException e){
+        e.printStackTrace();
+      }
     return null;
   }