qiaojialin commented on a change in pull request #818: [IOTDB-482] Vectorized 
TimeGenerator
URL: https://github.com/apache/incubator-iotdb/pull/818#discussion_r380040449
 
 

 ##########
 File path: 
tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
 ##########
 @@ -45,42 +50,78 @@ public boolean hasNext() throws IOException {
     if (hasCachedValue) {
       return true;
     }
-    if (leftChild.hasNext() && rightChild.hasNext()) {
-      long leftValue = leftChild.next();
-      long rightValue = rightChild.next();
-      while (true) {
-        if (leftValue == rightValue) {
-          this.hasCachedValue = true;
-          this.cachedValue = leftValue;
-          return true;
-        } else if (leftValue > rightValue) {
-          if (rightChild.hasNext()) {
-            rightValue = rightChild.next();
-          } else {
-            return false;
-          }
-        } else { // leftValue < rightValue
-          if (leftChild.hasNext()) {
-            leftValue = leftChild.next();
-          } else {
-            return false;
-          }
+    cachedValue = new TimeSeries(1000);
+    //fill data
+    fillLeftData();
+    fillRightData();
+    /*
+     *  [1,2,3,4,5]   <-   that was stopBatchTime mean
+     *  [1,2,3,4,5,6]
+     */
+    long stopBatchTime = getStopBatchTime();
+
+    while (leftPageData.hasMoreData() && rightPageData.hasMoreData()) {
+      long leftValue = leftPageData.currentTime();
+      long rightValue = rightPageData.currentTime();
+      if (leftValue == rightValue) {
+        this.hasCachedValue = true;
+        this.cachedValue.add(leftValue);
+        leftPageData.next();
+        rightPageData.next();
+      } else if (leftValue > rightValue) {
+        rightPageData.next();
+      } else { // leftValue < rightValue
+        leftPageData.next();
+      }
+
+      if (leftValue > stopBatchTime && rightValue > stopBatchTime) {
+        if (hasCachedValue) {
+          break;
         }
       }
+      /*
+       *  [1,2,3,4,5]   <-   reFill data and cal stopBatchTime
+       *             [6,7,8,9,10,11]
+       */
+      fillLeftData();
+      fillRightData();
+      stopBatchTime = getStopBatchTime();
     }
-    return false;
+    return hasCachedValue;
+  }
+
+  private long getStopBatchTime() {
+    long rMax = leftPageData.getLastTime();
+    long lMax = rightPageData.getLastTime();
+    return rMax > lMax ? lMax : rMax;
+  }
+
+  private void fillRightData() throws IOException {
+    if (hasMoreData(rightPageData, rightChild)) {
+      rightPageData = rightChild.next();
+    }
+  }
+
+  private void fillLeftData() throws IOException {
+    if (hasMoreData(leftPageData, leftChild)) {
+      leftPageData = leftChild.next();
+    }
+  }
+
+  private boolean hasMoreData(TimeSeries timeSeries, Node child) throws 
IOException {
 
 Review comment:
   add javadoc: no more data in cache and has more data in child

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to