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 10b0b8e020695..0ffe5f8d3913b 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 static Response fillQueryDataSet( 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 static Response fillQueryDataSet( } 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 static Response fillDataSetWithTimestamps( } return fillQueryDataSetWithTimestamps( - sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet); + sourceDataSet, + actualRowSizeLimit, + targetDataSetIndexToSourceDataSetIndex, + targetDataSet, + timePrecision); } public static Response fillLastQueryPlanDataSet( @@ -113,11 +121,16 @@ public static Response fillLastQueryPlanDataSet( 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 static Response fillGroupByLevelDataSet( sourceDataSet, targetDataSetIndexToSourceDataSetIndex, targetDataSet); return fillQueryDataSetWithTimestamps( - sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet); + sourceDataSet, + actualRowSizeLimit, + targetDataSetIndexToSourceDataSetIndex, + targetDataSet, + timePrecision); } private static Response fillAggregationPlanDataSet( @@ -195,7 +212,8 @@ private static Response fillQueryDataSetWithTimestamps( 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 @@ private static Response fillQueryDataSetWithTimestamps( } 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 91ee989de889d..49c0c7e147bb9 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 Response expression(ExpressionRequest expressionRequest, SecurityContext 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);