Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand All @@ -101,7 +105,11 @@ public static Response fillDataSetWithTimestamps(
}

return fillQueryDataSetWithTimestamps(
sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
sourceDataSet,
actualRowSizeLimit,
targetDataSetIndexToSourceDataSetIndex,
targetDataSet,
timePrecision);
}

public static Response fillLastQueryPlanDataSet(
Expand All @@ -113,19 +121,28 @@ 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();
initTargetDatasetExpByOrderWithSourceDataSet(
sourceDataSet, targetDataSetIndexToSourceDataSetIndex, targetDataSet);

return fillQueryDataSetWithTimestamps(
sourceDataSet, actualRowSizeLimit, targetDataSetIndexToSourceDataSetIndex, targetDataSet);
sourceDataSet,
actualRowSizeLimit,
targetDataSetIndexToSourceDataSetIndex,
targetDataSet,
timePrecision);
}

private static Response fillAggregationPlanDataSet(
Expand Down Expand Up @@ -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;

Expand All @@ -213,7 +231,10 @@ private static Response fillQueryDataSetWithTimestamps(
}

RowRecord sourceDataSetRowRecord = sourceDataSet.next();
targetDataSet.addTimestampsItem(sourceDataSetRowRecord.getTimestamp());
targetDataSet.addTimestampsItem(
timePrecision == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplifed to sourceDataSetRowRecord.getTimestamp() / timePrecision

? sourceDataSetRowRecord.getTimestamp()
: sourceDataSetRowRecord.getTimestamp() / timePrecision);
fillSourceRowRecordIntoTargetDataSet(
sourceDataSetRowRecord, targetDataSetIndexToSourceDataSetIndex, targetDataSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
Expand Down