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

hxd pushed a commit to branch rel/0.9
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/rel/0.9 by this push:
     new f9606b0  Added workaround when doing Aggregation over boolean Series.
f9606b0 is described below

commit f9606b0a042e7477365b5efd3ad9228343e99950
Author: Julian Feinauer <[email protected]>
AuthorDate: Sat May 2 09:47:35 2020 +0200

    Added workaround when doing Aggregation over boolean Series.
---
 .../iotdb/web/grafana/dao/impl/BasicDaoImpl.java   | 24 ++++++++++++++++++++++
 grafana/src/main/resources/application.properties  |  3 ++-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java 
b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
index 7af408f..dde404f 100644
--- 
a/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
+++ 
b/grafana/src/main/java/org/apache/iotdb/web/grafana/dao/impl/BasicDaoImpl.java
@@ -39,6 +39,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
@@ -48,6 +49,8 @@ public class BasicDaoImpl implements BasicDao {
 
   private static final Logger logger = 
LoggerFactory.getLogger(BasicDaoImpl.class);
 
+  public static final String FALLBACK_AGG_FUNCTION = "LAST";
+
   private final JdbcTemplate jdbcTemplate;
 
   private static long TIMESTAMP_RADIX = 1L;
@@ -98,8 +101,28 @@ public class BasicDaoImpl implements BasicDao {
     return (List<String>) jdbcTemplate.execute(connectionCallback);
   }
 
+  /**
+   * Note: If the query fails this could be due to AGGREGATIION like AVG on 
booleayn field.
+   * Thus, we then do a retry with FIRST aggregation.
+   * This should be solved better in the long run.
+   */
   @Override
   public List<TimeValues> querySeries(String s, Pair<ZonedDateTime, 
ZonedDateTime> timeRange) {
+    try {
+      return querySeriesInternal(s, timeRange, function);
+    } catch (Exception e) {
+      logger.info("Execution failed, trying now with FIRST Function!");
+      // Try it with FIRST
+      try {
+        return querySeriesInternal(s, timeRange, FALLBACK_AGG_FUNCTION);
+      } catch (Exception e2) {
+        logger.warn("Even FIRST query did not succeed, returning NULL now", 
e2);
+        return Collections.emptyList();
+      }
+    }
+  }
+
+  public List<TimeValues> querySeriesInternal(String s, Pair<ZonedDateTime, 
ZonedDateTime> timeRange, String function) {
     Long from = zonedCovertToLong(timeRange.left);
     Long to = zonedCovertToLong(timeRange.right);
     final long hours = Duration.between(timeRange.left, 
timeRange.right).toHours();
@@ -126,6 +149,7 @@ public class BasicDaoImpl implements BasicDao {
       rows = jdbcTemplate.query(sql, new TimeValuesRowMapper(columnName));
     } catch (Exception e) {
       logger.error(e.getMessage());
+      throw new RuntimeException("Query did not sucees", e);
     }
     return rows;
   }
diff --git a/grafana/src/main/resources/application.properties 
b/grafana/src/main/resources/application.properties
index 7847a8a..9401a32 100644
--- a/grafana/src/main/resources/application.properties
+++ b/grafana/src/main/resources/application.properties
@@ -32,4 +32,5 @@ isDownSampling=true
 interval=1m
 # aggregation function to use to downsampling the data
 # COUNT, FIRST_VALUE, LAST_VALUE, MAX_TIME, MAX_VALUE, AVG, MIN_TIME, 
MIN_VALUE, NOW, SUM
-function=avg
\ No newline at end of file
+# If it does fail (e.g. due to applying AVG to boolean) it will Fallback to 
LAST
+function=AVG
\ No newline at end of file

Reply via email to