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

 ##########
 File path: 
tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
 ##########
 @@ -19,80 +19,109 @@
 package org.apache.iotdb.tsfile.read.query.timegenerator.node;
 
 import java.io.IOException;
+import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.read.common.TimeColumn;
 
 public class OrNode implements Node {
 
+  private final int fetchSize = TSFileDescriptor.getInstance().getConfig()
+      .getBatchSize();
+
   private Node leftChild;
   private Node rightChild;
 
-  private boolean hasCachedLeftValue;
-  private long cachedLeftValue;
-  private boolean hasCachedRightValue;
-  private long cachedRightValue;
+  private TimeColumn leftTimeColumn;
+  private TimeColumn rightTimeColumn;
+
+  private TimeColumn cachedTimeColumn;
+  private boolean hasCachedValue;
+
 
   public OrNode(Node leftChild, Node rightChild) {
     this.leftChild = leftChild;
     this.rightChild = rightChild;
-    this.hasCachedLeftValue = false;
-    this.hasCachedRightValue = false;
   }
 
   @Override
-  public boolean hasNext() throws IOException {
-    if (hasCachedLeftValue || hasCachedRightValue) {
+  public boolean hasNextTimeColumn() throws IOException {
+    if (hasCachedValue) {
       return true;
     }
-    return leftChild.hasNext() || rightChild.hasNext();
-  }
 
-  private boolean hasLeftValue() throws IOException {
-    return hasCachedLeftValue || leftChild.hasNext();
+    return leftChild.hasNextTimeColumn() || rightChild.hasNextTimeColumn()
+        || leftTimeColumn.hasCurrent() || rightTimeColumn.hasCurrent();
   }
 
-  private long getLeftValue() throws IOException {
-    if (hasCachedLeftValue) {
-      hasCachedLeftValue = false;
-      return cachedLeftValue;
+  @Override
+  public TimeColumn nextTimeColumn() throws IOException {
+    if (hasCachedValue) {
+      hasCachedValue = false;
+      return cachedTimeColumn;
     }
-    return leftChild.next();
-  }
+    hasCachedValue = false;
+    cachedTimeColumn = new TimeColumn(fetchSize);
 
-  private boolean hasRightValue() throws IOException {
-    return hasCachedRightValue || rightChild.hasNext();
-  }
-
-  private long getRightValue() throws IOException {
-    if (hasCachedRightValue) {
-      hasCachedRightValue = false;
-      return cachedRightValue;
+    if (!hasLeftValue() && leftChild.hasNextTimeColumn()) {
+      leftTimeColumn = leftChild.nextTimeColumn();
+    }
+    if (!hasRightValue() && rightChild.hasNextTimeColumn()) {
+      rightTimeColumn = rightChild.nextTimeColumn();
     }
-    return rightChild.next();
-  }
 
-  @Override
-  public long next() throws IOException {
     if (hasLeftValue() && !hasRightValue()) {
-      return getLeftValue();
+      return leftTimeColumn;
     } else if (!hasLeftValue() && hasRightValue()) {
-      return getRightValue();
-    } else if (hasLeftValue() && hasRightValue()) {
-      long leftValue = getLeftValue();
-      long rightValue = getRightValue();
+      return rightTimeColumn;
+    }
+
+    while (hasLeftValue() && hasRightValue()) {
+      long leftValue = leftTimeColumn.currentTime();
+      long rightValue = rightTimeColumn.currentTime();
+
       if (leftValue < rightValue) {
-        hasCachedRightValue = true;
-        cachedRightValue = rightValue;
-        return leftValue;
+        hasCachedValue = true;
+        cachedTimeColumn.add(leftValue);
+        leftTimeColumn.next();
+        if (!leftTimeColumn.hasCurrent() && leftChild.hasNextTimeColumn()) {
+          leftTimeColumn = leftChild.nextTimeColumn();
+        }
       } else if (leftValue > rightValue) {
-        hasCachedLeftValue = true;
-        cachedLeftValue = leftValue;
-        return rightValue;
+        hasCachedValue = true;
+        cachedTimeColumn.add(rightValue);
+        rightTimeColumn.next();
+        if (!rightTimeColumn.hasCurrent() && rightChild.hasNextTimeColumn()) {
+          rightTimeColumn = rightChild.nextTimeColumn();
+        }
       } else {
-        return leftValue;
+        hasCachedValue = true;
+        cachedTimeColumn.add(leftValue);
+        leftTimeColumn.next();
+        rightTimeColumn.next();
+        if (!leftTimeColumn.hasCurrent() && leftChild.hasNextTimeColumn()) {
+          leftTimeColumn = leftChild.nextTimeColumn();
+        }
+        if (!rightTimeColumn.hasCurrent() && rightChild.hasNextTimeColumn()) {
+          rightTimeColumn = rightChild.nextTimeColumn();
+        }
+      }
+
+      if (cachedTimeColumn.size() >= fetchSize) {
+        break;
       }
     }
-    return -1;
+    hasCachedValue = false;
 
 Review comment:
   this field is unsless now

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