iotdb-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [iotdb] Alima777 commented on a change in pull request #2859: Optimize cluster query
Date Thu, 18 Mar 2021 11:31:45 GMT

Alima777 commented on a change in pull request #2859:
URL: https://github.com/apache/iotdb/pull/2859#discussion_r596774057



##########
File path: server/src/main/java/org/apache/iotdb/db/query/externalsort/adapter/ByTimestampReaderAdapter.java
##########
@@ -32,34 +32,40 @@
   // only cache the first point that >= timestamp
   private boolean hasCached;
   private TimeValuePair pair;
+  private long currentTime = Long.MIN_VALUE;
 
   public ByTimestampReaderAdapter(IPointReader pointReader) {
     this.pointReader = pointReader;
   }
 
   @Override
-  public Object getValueInTimestamp(long timestamp) throws IOException {
-    if (hasCached) {
-      if (pair.getTimestamp() < timestamp) {
-        hasCached = false;
-      } else if (pair.getTimestamp() == timestamp) {
-        hasCached = false;
-        return pair.getValue().getValue();
-      } else {
-        return null;
-      }
-    }
+  public Object[] getValuesInTimestamps(long[] timestamps, int length) throws IOException
{
+    Object[] result = new Object[length];
 
-    while (pointReader.hasNextTimeValuePair()) {
-      pair = pointReader.nextTimeValuePair();
-      if (pair.getTimestamp() == timestamp) {
-        return pair.getValue().getValue();
-      } else if (pair.getTimestamp() > timestamp) {
-        hasCached = true;
-        return null;
+    for (int i = 0; i < length; i++) {
+      if (timestamps[i] < currentTime) {
+        throw new IOException("time must be increasing when use ReaderByTimestamp");
+      }
+      currentTime = timestamps[i];
+      // search cache
+      if (hasCached && pair.getTimestamp() >= currentTime) {
+        if (pair.getTimestamp() == currentTime) {
+          hasCached = false;
+          result[i] = pair.getValue().getValue();
+        }
+        continue;
+      }
+      // search reader
+      while (pointReader.hasNextTimeValuePair()) {
+        pair = pointReader.nextTimeValuePair();
+        if (pair.getTimestamp() == currentTime) {
+          result[i] = pair.getValue().getValue();
+        } else if (pair.getTimestamp() > currentTime) {
+          hasCached = true;
+          result[i] = null;
+        }
       }
     }
-
-    return null;
+    return result;

Review comment:
       You are right~




----------------------------------------------------------------
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.

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



Mime
View raw message