You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/02/16 11:34:57 UTC

[GitHub] [iotdb] JackieTien97 commented on a change in pull request #5063: [IOTDB-2543] Support le & lt filters in last query

JackieTien97 commented on a change in pull request #5063:
URL: https://github.com/apache/iotdb/pull/5063#discussion_r807837062



##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -171,8 +175,9 @@ public QueryDataSet execute(QueryContext context, LastQueryPlan lastQueryPlan)
             nonCachedPaths,
             nonCachedDataTypes,
             context.isDebug());
+
     if (nonCachedPaths.isEmpty()) {
-      return resultContainer;
+      return cachedLastPairs.stream().map(pair -> pair.right).collect(Collectors.toList());

Review comment:
       Actually, the reason that we directly return the resultContainer is that we want to reuse it instead of creating another ArrayList, even if the pair.left will never be used. It is for performance. If you really want to not return extra result, you can make readLastPairsFromCache to return Pair<boolean[], List<TimeValuePair>> instead and return res.right.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/executor/LastQueryExecutor.java
##########
@@ -215,26 +220,35 @@ public QueryDataSet execute(QueryContext context, LastQueryPlan lastQueryPlan)
 
     // Compute Last result for the rest series paths by scanning Tsfiles
     int index = 0;
-    for (int i = 0; i < resultContainer.size(); i++) {
-      if (Boolean.FALSE.equals(resultContainer.get(i).left)) {
-        resultContainer.get(i).right = readerList.get(index++).readLastPoint();
-        if (resultContainer.get(i).right.getValue() != null) {
-          resultContainer.get(i).left = true;
-          if (CACHE_ENABLED) {
-            cacheAccessors.get(i).write(resultContainer.get(i).right);
-            if (context.isDebug()) {
-              DEBUG_LOGGER.info(
-                  "[LastQueryExecutor] Update last cache for path: {} with timestamp: {}",
-                  seriesPaths,
-                  resultContainer.get(i).right.getTimestamp());
-            }
+    for (int i = 0; i < cachedLastPairs.size(); i++) {
+      if (cachedLastPairs.get(i).right == null) {

Review comment:
       Here, if the filter is gt (greater than) or ge (greater than or equal to) and cachedLastPairs.get(i).left is Boolean.TRUE, we don't need to read from disk again.

##########
File path: docs/UserGuide/Query-Data/Last-Query.md
##########
@@ -21,27 +21,27 @@
 
 # Last Query
 
-The last query is a special query provided in the time series database Apache IoTDB. The last query returns the data point with the largest timestamp in the time series, that is, the latest state of a sequence. Users can specify the last query through `select last`. It is especially important in IoT data analysis scenarios as the latest point data characterizes the current state. In order to provide a millisecond-level return speed, Apache IoTDB optimizes the cache for the last query to meet users' performance requirements for real-time monitoring of devices.
+The last query is a special type of query in Apache IoTDB. It returns the data point with the largest timestamp of the specified time series. In other word, it returns the latest state of a time series. This feature is especially important in IoT data analysis scenarios. To meets the performance requirement of real-time device monitoring systems, Apache IoTDB caches the latest values of all time series to achieve microsecond read latency.

Review comment:
       ```suggestion
   The last query is a special type of query in Apache IoTDB. It returns the data point with the largest timestamp of the specified time series. In other word, it returns the latest state of a time series. This feature is especially important in IoT data analysis scenarios. To meet the performance requirement of real-time device monitoring systems, Apache IoTDB caches the latest values of all time series to achieve microsecond read latency.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org