You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/02/08 11:03:36 UTC

[iotdb] branch master updated: [IOTDB-2518] fixed grafana plugin not support microsecond or nanosecond (#5017)

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

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ff0e11  [IOTDB-2518] fixed grafana plugin not support microsecond or nanosecond (#5017)
1ff0e11 is described below

commit 1ff0e119f2914e2d3b2ac4170af787e810dbe821
Author: CloudWise-Lukemiao <76...@users.noreply.github.com>
AuthorDate: Tue Feb 8 19:02:54 2022 +0800

    [IOTDB-2518] fixed grafana plugin not support microsecond or nanosecond (#5017)
---
 .../protocol/rest/handler/QueryDataSetHandler.java | 39 +++++++++++++++++-----
 .../protocol/rest/impl/GrafanaApiServiceImpl.java  | 15 ++++-----
 2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/QueryDataSetHandler.java b/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/QueryDataSetHandler.java
index 10b0b8e..0ffe5f8 100644
--- a/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/QueryDataSetHandler.java
+++ b/server/src/main/java/org/apache/iotdb/db/protocol/rest/handler/QueryDataSetHandler.java
@@ -68,9 +68,10 @@ public class QueryDataSetHandler {
       return fillAggregationPlanDataSet(
           sourceDataSet, (AggregationPlan) physicalPlan, actualRowSizeLimit);
     } else if (sourceDataSet instanceof GroupByLevelDataSet) {
-      return fillGroupByLevelDataSet(sourceDataSet, actualRowSizeLimit);
+      return fillGroupByLevelDataSet(sourceDataSet, actualRowSizeLimit, 1);
     } else if (physicalPlan instanceof QueryPlan) {
-      return fillDataSetWithTimestamps(sourceDataSet, (QueryPlan) physicalPlan, actualRowSizeLimit);
+      return fillDataSetWithTimestamps(
+          sourceDataSet, (QueryPlan) physicalPlan, actualRowSizeLimit, 1);
     } else {
       return Response.ok()
           .entity(
@@ -84,7 +85,10 @@ public class QueryDataSetHandler {
   }
 
   public static Response fillDataSetWithTimestamps(
-      QueryDataSet sourceDataSet, QueryPlan queryPlan, final int actualRowSizeLimit)
+      QueryDataSet sourceDataSet,
+      QueryPlan queryPlan,
+      final int actualRowSizeLimit,
+      final long timePrecision)
       throws IOException {
     org.apache.iotdb.db.protocol.rest.model.QueryDataSet targetDataSet =
         new org.apache.iotdb.db.protocol.rest.model.QueryDataSet();
@@ -101,7 +105,11 @@ public class QueryDataSetHandler {
     }
 
     return fillQueryDataSetWithTimestamps(
-        sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
+        sourceDataSet,
+        actualRowSizeLimit,
+        targetDataSetIndexToSourceDataSetIndex,
+        targetDataSet,
+        timePrecision);
   }
 
   public static Response fillLastQueryPlanDataSet(
@@ -113,11 +121,16 @@ public class QueryDataSetHandler {
         sourceDataSet, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
 
     return fillQueryDataSetWithTimestamps(
-        sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
+        sourceDataSet,
+        actualRowSizeLimit,
+        targetDataSetIndexToSourceDataSetIndex,
+        targetDataSet,
+        1);
   }
 
   public static Response fillGroupByLevelDataSet(
-      QueryDataSet sourceDataSet, final int actualRowSizeLimit) throws IOException {
+      QueryDataSet sourceDataSet, final int actualRowSizeLimit, final long timePrecision)
+      throws IOException {
     int[] targetDataSetIndexToSourceDataSetIndex = new int[sourceDataSet.getPaths().size()];
     org.apache.iotdb.db.protocol.rest.model.QueryDataSet targetDataSet =
         new org.apache.iotdb.db.protocol.rest.model.QueryDataSet();
@@ -125,7 +138,11 @@ public class QueryDataSetHandler {
         sourceDataSet, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
 
     return fillQueryDataSetWithTimestamps(
-        sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
+        sourceDataSet,
+        actualRowSizeLimit,
+        targetDataSetIndexToSourceDataSetIndex,
+        targetDataSet,
+        timePrecision);
   }
 
   private static Response fillAggregationPlanDataSet(
@@ -195,7 +212,8 @@ public class QueryDataSetHandler {
       QueryDataSet sourceDataSet,
       int actualRowSizeLimit,
       int[] targetDataSetIndexToSourceDataSetIndex,
-      org.apache.iotdb.db.protocol.rest.model.QueryDataSet targetDataSet)
+      org.apache.iotdb.db.protocol.rest.model.QueryDataSet targetDataSet,
+      final long timePrecision)
       throws IOException {
     int fetched = 0;
 
@@ -213,7 +231,10 @@ public class QueryDataSetHandler {
       }
 
       RowRecord sourceDataSetRowRecord = sourceDataSet.next();
-      targetDataSet.addTimestampsItem(sourceDataSetRowRecord.getTimestamp());
+      targetDataSet.addTimestampsItem(
+          timePrecision == 1
+              ? sourceDataSetRowRecord.getTimestamp()
+              : sourceDataSetRowRecord.getTimestamp() / timePrecision);
       fillSourceRowRecordIntoTargetDataSet(
           sourceDataSetRowRecord, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
 
diff --git a/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/GrafanaApiServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/GrafanaApiServiceImpl.java
index 91ee989..49c0c7e 100644
--- a/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/GrafanaApiServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/protocol/rest/impl/GrafanaApiServiceImpl.java
@@ -52,23 +52,20 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
   private final ServiceProvider serviceProvider = IoTDB.serviceProvider;
   private final AuthorizationHandler authorizationHandler;
 
-  private final float timePrecision; // the default timestamp precision is ms
+  private final long timePrecision; // the default timestamp precision is ms
 
   public GrafanaApiServiceImpl() throws QueryProcessException {
     authorizationHandler = new AuthorizationHandler(serviceProvider);
 
     switch (IoTDBDescriptor.getInstance().getConfig().getTimestampPrecision()) {
       case "ns":
-        timePrecision = 1000000f;
+        timePrecision = 1000000;
         break;
       case "us":
-        timePrecision = 1000f;
-        break;
-      case "s":
-        timePrecision = 1f / 1000;
+        timePrecision = 1000;
         break;
       default:
-        timePrecision = 1f;
+        timePrecision = 1;
     }
   }
 
@@ -162,10 +159,10 @@ public class GrafanaApiServiceImpl extends GrafanaApiService {
                 queryContext, physicalPlan, IoTDBConstant.DEFAULT_FETCH_SIZE);
 
         if (queryDataSet instanceof GroupByLevelDataSet) {
-          return QueryDataSetHandler.fillGroupByLevelDataSet(queryDataSet, 0);
+          return QueryDataSetHandler.fillGroupByLevelDataSet(queryDataSet, 0, timePrecision);
         } else {
           return QueryDataSetHandler.fillDataSetWithTimestamps(
-              queryDataSet, (QueryPlan) physicalPlan, 0);
+              queryDataSet, (QueryPlan) physicalPlan, 0, timePrecision);
         }
       } finally {
         ServiceProvider.SESSION_MANAGER.releaseQueryResourceNoExceptions(queryId);