This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 7d350ba  rollback TimeGenerator (#964)
7d350ba is described below

commit 7d350bae1591f7ead2d4ade5a3a97eef2f7f2123
Author: Dawei Liu <[email protected]>
AuthorDate: Wed Apr 1 19:46:05 2020 +0800

    rollback TimeGenerator (#964)
    
    * rollback TimeGenerator to point iterator
---
 .../adapter/ByTimestampReaderAdapter.java          |  46 ++++----
 .../reader/chunk/DiskChunkReaderByTimestamp.java   |  55 +++++-----
 .../db/query/reader/series/IReaderByTimestamp.java |  14 +--
 .../reader/series/SeriesReaderByTimestamp.java     |  24 ++---
 .../writelog/recover/UnseqTsFileRecoverTest.java   |   3 +-
 .../read/query/timegenerator/TimeGenerator.java    |  39 ++-----
 .../read/query/timegenerator/node/AndNode.java     |  96 +++++------------
 .../read/query/timegenerator/node/LeafNode.java    |  65 +++++------
 .../tsfile/read/query/timegenerator/node/Node.java |   5 +-
 .../read/query/timegenerator/node/OrNode.java      | 119 ++++++++-------------
 .../tsfile/read/query/timegenerator/NodeTest.java  |  30 ++----
 11 files changed, 185 insertions(+), 311 deletions(-)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/externalsort/adapter/ByTimestampReaderAdapter.java
 
b/server/src/main/java/org/apache/iotdb/db/query/externalsort/adapter/ByTimestampReaderAdapter.java
index d7cc172..df1b4f4 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/externalsort/adapter/ByTimestampReaderAdapter.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/externalsort/adapter/ByTimestampReaderAdapter.java
@@ -33,40 +33,34 @@ public class ByTimestampReaderAdapter implements 
IReaderByTimestamp {
   // 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[] getValuesInTimestamps(long[] timestamps) throws IOException {
-    Object[] result = new Object[timestamps.length];
-
-    for (int i = 0; i < timestamps.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;
+  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;
       }
-      // 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;
-        }
+    }
+
+    while (pointReader.hasNextTimeValuePair()) {
+      pair = pointReader.nextTimeValuePair();
+      if (pair.getTimestamp() == timestamp) {
+        return pair.getValue().getValue();
+      } else if (pair.getTimestamp() > timestamp) {
+        hasCached = true;
+        return null;
       }
     }
-    return result;
+
+    return null;
   }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/DiskChunkReaderByTimestamp.java
 
b/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/DiskChunkReaderByTimestamp.java
index 07873a2..4217638 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/DiskChunkReaderByTimestamp.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/reader/chunk/DiskChunkReaderByTimestamp.java
@@ -33,49 +33,46 @@ public class DiskChunkReaderByTimestamp implements 
IReaderByTimestamp {
 
   private ChunkReaderByTimestamp chunkReaderByTimestamp;
   private BatchData data;
-  private long currentTime = Long.MIN_VALUE;
 
   public DiskChunkReaderByTimestamp(ChunkReaderByTimestamp 
chunkReaderByTimestamp) {
     this.chunkReaderByTimestamp = chunkReaderByTimestamp;
   }
 
   @Override
-  public Object[] getValuesInTimestamps(long[] timestamps) throws IOException {
-    Object[] result = new Object[timestamps.length];
+  public Object getValueInTimestamp(long timestamp) throws IOException {
 
-    for (int i = 0; i < timestamps.length; i++) {
-      if (timestamps[i] < currentTime) {
-        throw new IOException("time must be increasing when use 
ReaderByTimestamp");
+    if (!hasNext()) {
+      return null;
+    }
+
+    while (data != null) {
+      Object value = data.getValueInTimestamp(timestamp);
+      if (value != null) {
+        return value;
       }
-      currentTime = timestamps[i];
-      while (hasNext()) {
-        data = next();
-        if (data.getMaxTimestamp() > currentTime) {
-          result[i] = null;
-          break;
-        }
-        result[i] = data.getValueInTimestamp(currentTime);
-        //fill cache
-        if (!data.hasCurrent() && 
chunkReaderByTimestamp.hasNextSatisfiedPage()) {
-          data = next();
+      if (data.hasCurrent()) {
+        return null;
+      } else {
+        chunkReaderByTimestamp.setCurrentTimestamp(timestamp);
+        if (chunkReaderByTimestamp.hasNextSatisfiedPage()) {
+          data = chunkReaderByTimestamp.nextPageData();
+        } else {
+          return null;
         }
       }
     }
-    return result;
-  }
 
-  private boolean hasCacheData() {
-    return data != null && data.hasCurrent();
+    return null;
   }
 
-  private boolean hasNext() {
-    return hasCacheData() || chunkReaderByTimestamp.hasNextSatisfiedPage();
-  }
-
-  private BatchData next() throws IOException {
-    if (hasCacheData()) {
-      return data;
+  private boolean hasNext() throws IOException {
+    if (data != null && data.hasCurrent()) {
+      return true;
+    }
+    if (chunkReaderByTimestamp != null && 
chunkReaderByTimestamp.hasNextSatisfiedPage()) {
+      data = chunkReaderByTimestamp.nextPageData();
+      return true;
     }
-    return chunkReaderByTimestamp.nextPageData();
+    return false;
   }
 }
\ No newline at end of file
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/reader/series/IReaderByTimestamp.java
 
b/server/src/main/java/org/apache/iotdb/db/query/reader/series/IReaderByTimestamp.java
index a60f943..cb924ef 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/reader/series/IReaderByTimestamp.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/reader/series/IReaderByTimestamp.java
@@ -23,21 +23,13 @@ import java.io.IOException;
 public interface IReaderByTimestamp {
 
   /**
-   * Returns the corresponding value under this timestamp. Returns null if no 
value under this
-   * timestamp.
+   * Returns the corresponding value under this timestamp. Returns null if no 
value under this timestamp.
    * <p>
    * Note that calling this method will change the status of this reader 
irreversibly just like
    * <code>next</code>. The difference is that <code>next</code> moves one 
step forward while
    * <code>getValueInTimestamp</code> advances towards the given timestamp.
    * <p>
-   * Attention: DO call this method with monotonically increasing timestamps. 
There is no guarantee
-   * of correctness with any other way of calling. For example, DO NOT call 
this method twice with
-   * the same timestamp.
+   * Attention: DO call this method with monotonically increasing timestamps. 
There is no guarantee of correctness with any other way of calling. For 
example, DO NOT call this method twice with the same timestamp.
    */
-  default Object getValueInTimestamp(long timestamp) throws IOException {
-    Object[] values = getValuesInTimestamps(new long[]{timestamp});
-    return values[0];
-  }
-
-  Object[] getValuesInTimestamps(long[] timestamps) throws IOException;
+  Object getValueInTimestamp(long timestamp) throws IOException;
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
 
b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
index b0853bf..e7f5da6 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
@@ -34,7 +34,6 @@ public class SeriesReaderByTimestamp implements 
IReaderByTimestamp {
 
   private SeriesReader seriesReader;
   private BatchData batchData;
-  private long currentTime = Long.MIN_VALUE;
 
   public SeriesReaderByTimestamp(Path seriesPath, Set<String> allSensors,  
TSDataType dataType, QueryContext context,
                                  QueryDataSource dataSource, TsFileFilter 
fileFilter) {
@@ -47,23 +46,14 @@ public class SeriesReaderByTimestamp implements 
IReaderByTimestamp {
   }
 
   @Override
-  public Object[] getValuesInTimestamps(long[] timestamps) throws IOException {
-    Object[] result = new Object[timestamps.length];
-
-    for (int i = 0; i < timestamps.length; i++) {
-      if (timestamps[i] < currentTime) {
-        throw new IOException("time must be increasing when use 
ReaderByTimestamp");
-      }
-      currentTime = timestamps[i];
-      seriesReader.setTimeFilter(currentTime);
-      if ((batchData == null || batchData.getMaxTimestamp() < currentTime)
-          && !hasNext(currentTime)) {
-        result[i] = null;
-        continue;
-      }
-      result[i] = batchData.getValueInTimestamp(currentTime);
+  public Object getValueInTimestamp(long timestamp) throws IOException {
+    seriesReader.setTimeFilter(timestamp);
+    if ((batchData == null || batchData.getTimeByIndex(batchData.length() - 1) 
< timestamp)
+        && !hasNext(timestamp)) {
+      return null;
     }
-    return result;
+
+    return batchData.getValueInTimestamp(timestamp);
   }
 
   private boolean hasNext(long timestamp) throws IOException {
diff --git 
a/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java
 
b/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java
index 9eac04d..16994df 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/writelog/recover/UnseqTsFileRecoverTest.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.db.writelog.recover;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.iotdb.db.conf.adapter.ActiveTimeSeriesCounter;
+import org.apache.iotdb.db.constant.TestConstant;
 import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
 import org.apache.iotdb.db.engine.flush.pool.FlushSubTaskPoolManager;
 import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
@@ -67,7 +68,7 @@ public class UnseqTsFileRecoverTest {
   private File tsF;
   private TsFileWriter writer;
   private WriteLogNode node;
-  private String logNodePrefix = "testNode/0";
+  private String logNodePrefix = 
TestConstant.OUTPUT_DATA_DIR.concat("testNode/0");
   private Schema schema;
   private TsFileResource resource;
   private VersionController versionController = new VersionController() {
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/TimeGenerator.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/TimeGenerator.java
index 527f3c0..8c11b4b 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/TimeGenerator.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/TimeGenerator.java
@@ -35,52 +35,29 @@ import java.io.IOException;
 import java.util.*;
 
 /**
- * All SingleSeriesExpression involved in a IExpression will be transferred to 
a TimeGenerator tree
- * whose leaf nodes are all SeriesReaders, The TimeGenerator tree can generate 
the next timestamp
- * that satisfies the filter condition. Then we use this timestamp to get 
values in other series
- * that are not included in IExpression
+ * All SingleSeriesExpression involved in a IExpression will be transferred to 
a TimeGenerator tree whose leaf nodes are all SeriesReaders, The TimeGenerator 
tree can generate the next timestamp that satisfies the filter condition. Then 
we use this timestamp to get values in other series that are not included in 
IExpression
  */
 public abstract class TimeGenerator {
 
-
-  private boolean hasCache;
-  private TimeColumn cacheTimes;
-
   private HashMap<Path, List<LeafNode>> leafCache = new HashMap<>();
   private Node operatorNode;
 
   public boolean hasNext() throws IOException {
-    if (hasCache) {
-      return true;
-    }
-
-    while (operatorNode.hasNextTimeColumn()) {
-      cacheTimes = operatorNode.nextTimeColumn();
-      if (cacheTimes.hasCurrent()) {
-        hasCache = true;
-        break;
-      }
-    }
-    return hasCache;
+    return operatorNode.hasNext();
   }
 
   public long next() throws IOException {
-    if (hasCache || hasNext()) {
-      long currentTime = cacheTimes.currentTime();
-      cacheTimes.next();
-      hasCache = cacheTimes.hasCurrent();
-      return currentTime;
-    }
-    throw new IOException("no more data");
+    return operatorNode.next();
   }
 
   public Object getValue(Path path, long time) {
     for (LeafNode leafNode : leafCache.get(path)) {
-      Object value = leafNode.currentValue(time);
-      if (value != null) {
-        return value;
+      if (!leafNode.currentTimeIs(time)) {
+        continue;
       }
+      return leafNode.currentValue();
     }
+
     return null;
   }
 
@@ -117,7 +94,7 @@ public abstract class TimeGenerator {
         return new AndNode(leftChild, rightChild);
       }
       throw new UnSupportedDataTypeException(
-              "Unsupported ExpressionType when construct OperatorNode: " + 
expression.getType());
+          "Unsupported ExpressionType when construct OperatorNode: " + 
expression.getType());
     }
   }
 
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
index 650a741..e44c383 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/AndNode.java
@@ -19,23 +19,15 @@
 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 AndNode implements Node {
 
-  private final int fetchSize = 
TSFileDescriptor.getInstance().getConfig().getBatchSize();
-
   private Node leftChild;
   private Node rightChild;
 
-  private TimeColumn cachedTimeColumn;
+  private long cachedValue;
   private boolean hasCachedValue;
 
-  private TimeColumn leftTimeColumn;
-  private TimeColumn rightTimeColumn;
-
-
   /**
    * Constructor of AndNode.
    *
@@ -49,76 +41,44 @@ public class AndNode implements Node {
   }
 
   @Override
-  public boolean hasNextTimeColumn() throws IOException {
+  public boolean hasNext() throws IOException {
     if (hasCachedValue) {
       return true;
     }
-    cachedTimeColumn = new TimeColumn();
-    //fill data
-    fillLeftCache();
-    fillRightCache();
-
-    if (!hasLeftValue() || !hasRightValue()) {
-      return false;
-    }
-
-    while (leftTimeColumn.hasCurrent() && rightTimeColumn.hasCurrent()) {
-      long leftValue = leftTimeColumn.currentTime();
-      long rightValue = rightTimeColumn.currentTime();
-
-      if (leftValue == rightValue) {
-        this.hasCachedValue = true;
-        this.cachedTimeColumn.add(leftValue);
-        leftTimeColumn.next();
-        rightTimeColumn.next();
-      } else if (leftValue > rightValue) {
-        rightTimeColumn.next();
-      } else { // leftValue < rightValue
-        leftTimeColumn.next();
-      }
-
-      if (cachedTimeColumn.size() >= fetchSize) {
-        break;
+    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;
+          }
+        }
       }
-      fillLeftCache();
-      fillRightCache();
     }
-    return hasCachedValue;
-  }
-
-  private void fillRightCache() throws IOException {
-    if (couldFillCache(rightTimeColumn, rightChild)) {
-      rightTimeColumn = rightChild.nextTimeColumn();
-    }
-  }
-
-  private void fillLeftCache() throws IOException {
-    if (couldFillCache(leftTimeColumn, leftChild)) {
-      leftTimeColumn = leftChild.nextTimeColumn();
-    }
-  }
-
-  private boolean hasLeftValue() {
-    return leftTimeColumn != null && leftTimeColumn.hasCurrent();
-  }
-
-  private boolean hasRightValue() {
-    return rightTimeColumn != null && rightTimeColumn.hasCurrent();
-  }
-
-  //no more data in cache and has more data in child
-  private boolean couldFillCache(TimeColumn timeSeries, Node child) throws 
IOException {
-    return (timeSeries == null || !timeSeries.hasCurrent()) && 
child.hasNextTimeColumn();
+    return false;
   }
 
   /**
    * If there is no value in current Node, -1 will be returned if {@code 
next()} is invoked.
    */
   @Override
-  public TimeColumn nextTimeColumn() throws IOException {
-    if (hasCachedValue || hasNextTimeColumn()) {
+  public long next() throws IOException {
+    if (hasNext()) {
       hasCachedValue = false;
-      return cachedTimeColumn;
+      return cachedValue;
     }
     throw new IOException("no more data");
   }
@@ -127,4 +87,4 @@ public class AndNode implements Node {
   public NodeType getType() {
     return NodeType.AND;
   }
-}
\ No newline at end of file
+}
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
index 4263732..d4b4be3 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/LeafNode.java
@@ -19,8 +19,6 @@
 package org.apache.iotdb.tsfile.read.query.timegenerator.node;
 
 import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
 import org.apache.iotdb.tsfile.read.common.BatchData;
 import org.apache.iotdb.tsfile.read.common.TimeColumn;
 import org.apache.iotdb.tsfile.read.reader.IBatchReader;
@@ -29,57 +27,64 @@ public class LeafNode implements Node {
 
   private IBatchReader reader;
 
-  private List<BatchData> batchDataList = new LinkedList<>();
-  private TimeColumn cachedTimeSeries;
+  private BatchData cacheData;
   private boolean hasCached;
 
+  private long cachedTime;
+  private Object cachedValue;
+
   public LeafNode(IBatchReader reader) {
     this.reader = reader;
   }
 
   @Override
-  public boolean hasNextTimeColumn() throws IOException {
+  public boolean hasNext() throws IOException {
     if (hasCached) {
       return true;
     }
-    while (reader.hasNextBatch()) {
-      BatchData currentBatch = reader.nextBatch();
-      if (currentBatch.hasCurrent()) {
-        batchDataList.add(currentBatch);
+    if (cacheData != null && cacheData.hasCurrent()) {
+      cachedTime = cacheData.currentTime();
+      cachedValue = cacheData.currentValue();
+      hasCached = true;
+      return true;
+    }
+    if (reader.hasNextBatch()) {
+      cacheData = reader.nextBatch();
+      if (cacheData.hasCurrent()) {
+        cachedTime = cacheData.currentTime();
+        cachedValue = cacheData.currentValue();
         hasCached = true;
-        cachedTimeSeries = currentBatch.getTimeColumn();
-        break;
+        return true;
       }
     }
-    return hasCached;
+    return false;
   }
 
   @Override
-  public TimeColumn nextTimeColumn() throws IOException {
-    if (hasCached || hasNextTimeColumn()) {
+  public long next() throws IOException {
+    if ((hasCached || hasNext())) {
       hasCached = false;
-      return cachedTimeSeries;
+      cacheData.next();
+      return cachedTime;
     }
     throw new IOException("no more data");
   }
 
   /**
+   * Check whether the current time equals the given time.
+   *
+   * @param time the given time
+   * @return True if the current time equals the given time. False if not.
+   */
+  public boolean currentTimeIs(long time) {
+    return cachedTime == time;
+  }
+
+  /**
    * Function for getting the value at the given time.
    */
-  public Object currentValue(long time) {
-    while (!batchDataList.isEmpty()) {
-      BatchData oldestBatch = batchDataList.get(0);
-      Object value = oldestBatch.getValueInTimestamp(time);
-      if (value != null) {
-        return value;
-      }
-      if (!oldestBatch.hasCurrent()) {
-        batchDataList.remove(0);
-      } else {
-        return null;
-      }
-    }
-    return null;
+  public Object currentValue() {
+    return cachedValue;
   }
 
   @Override
@@ -87,4 +92,4 @@ public class LeafNode implements Node {
     return NodeType.LEAF;
   }
 
-}
\ No newline at end of file
+}
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/Node.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/Node.java
index aa8c850..bacc7ed 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/Node.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/Node.java
@@ -19,13 +19,12 @@
 package org.apache.iotdb.tsfile.read.query.timegenerator.node;
 
 import java.io.IOException;
-import org.apache.iotdb.tsfile.read.common.TimeColumn;
 
 public interface Node {
 
-  boolean hasNextTimeColumn() throws IOException;
+  boolean hasNext() throws IOException;
 
-  TimeColumn nextTimeColumn() throws IOException;
+  long next() throws IOException;
 
   NodeType getType();
 }
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
index b9d2eb8..510a06c 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
@@ -19,109 +19,80 @@
 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 TimeColumn leftTimeColumn;
-  private TimeColumn rightTimeColumn;
-
-  private TimeColumn cachedTimeColumn;
-  private boolean hasCachedValue;
-
+  private boolean hasCachedLeftValue;
+  private long cachedLeftValue;
+  private boolean hasCachedRightValue;
+  private long cachedRightValue;
 
   public OrNode(Node leftChild, Node rightChild) {
     this.leftChild = leftChild;
     this.rightChild = rightChild;
+    this.hasCachedLeftValue = false;
+    this.hasCachedRightValue = false;
   }
 
   @Override
-  public boolean hasNextTimeColumn() throws IOException {
-    if (hasCachedValue) {
+  public boolean hasNext() throws IOException {
+    if (hasCachedLeftValue || hasCachedRightValue) {
       return true;
     }
+    return leftChild.hasNext() || rightChild.hasNext();
+  }
 
-    if (!hasLeftValue() && leftChild.hasNextTimeColumn()) {
-      leftTimeColumn = leftChild.nextTimeColumn();
-    }
-    if (!hasRightValue() && rightChild.hasNextTimeColumn()) {
-      rightTimeColumn = rightChild.nextTimeColumn();
-    }
+  private boolean hasLeftValue() throws IOException {
+    return hasCachedLeftValue || leftChild.hasNext();
+  }
 
-    if (hasLeftValue() && !hasRightValue()) {
-      cachedTimeColumn = leftTimeColumn;
-      hasCachedValue = true;
-      return true;
-    } else if (!hasLeftValue() && hasRightValue()) {
-      cachedTimeColumn = rightTimeColumn;
-      hasCachedValue = true;
-      return true;
+  private long getLeftValue() throws IOException {
+    if (hasCachedLeftValue) {
+      hasCachedLeftValue = false;
+      return cachedLeftValue;
     }
+    return leftChild.next();
+  }
 
-    cachedTimeColumn = new TimeColumn();
+  private boolean hasRightValue() throws IOException {
+    return hasCachedRightValue || rightChild.hasNext();
+  }
 
-    while (hasLeftValue() && hasRightValue()) {
-      long leftValue = leftTimeColumn.currentTime();
-      long rightValue = rightTimeColumn.currentTime();
+  private long getRightValue() throws IOException {
+    if (hasCachedRightValue) {
+      hasCachedRightValue = false;
+      return cachedRightValue;
+    }
+    return rightChild.next();
+  }
 
+  @Override
+  public long next() throws IOException {
+    if (hasLeftValue() && !hasRightValue()) {
+      return getLeftValue();
+    } else if (!hasLeftValue() && hasRightValue()) {
+      return getRightValue();
+    } else if (hasLeftValue() && hasRightValue()) {
+      long leftValue = getLeftValue();
+      long rightValue = getRightValue();
       if (leftValue < rightValue) {
-        hasCachedValue = true;
-        cachedTimeColumn.add(leftValue);
-        leftTimeColumn.next();
-        if (!leftTimeColumn.hasCurrent() && leftChild.hasNextTimeColumn()) {
-          leftTimeColumn = leftChild.nextTimeColumn();
-        }
+        hasCachedRightValue = true;
+        cachedRightValue = rightValue;
+        return leftValue;
       } else if (leftValue > rightValue) {
-        hasCachedValue = true;
-        cachedTimeColumn.add(rightValue);
-        rightTimeColumn.next();
-        if (!rightTimeColumn.hasCurrent() && rightChild.hasNextTimeColumn()) {
-          rightTimeColumn = rightChild.nextTimeColumn();
-        }
+        hasCachedLeftValue = true;
+        cachedLeftValue = leftValue;
+        return rightValue;
       } else {
-        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();
-        }
+        return leftValue;
       }
-
-      if (cachedTimeColumn.size() >= fetchSize) {
-        break;
-      }
-    }
-    return hasCachedValue;
-  }
-
-  @Override
-  public TimeColumn nextTimeColumn() throws IOException {
-    if (hasCachedValue || hasNextTimeColumn()) {
-      hasCachedValue = false;
-      return cachedTimeColumn;
     }
     throw new IOException("no more data");
   }
 
-  private boolean hasLeftValue() {
-    return leftTimeColumn != null && leftTimeColumn.hasCurrent();
-  }
-
-  private boolean hasRightValue() {
-    return rightTimeColumn != null && rightTimeColumn.hasCurrent();
-  }
-
-
   @Override
   public NodeType getType() {
     return NodeType.OR;
diff --git 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
index 6037993..db67ec6 100644
--- 
a/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
+++ 
b/tsfile/src/test/java/org/apache/iotdb/tsfile/read/query/timegenerator/NodeTest.java
@@ -43,17 +43,13 @@ public class NodeTest {
 
   @Test
   public void testLeafNode() throws IOException {
+    int index = 0;
     long[] timestamps = new long[]{1, 2, 3, 4, 5, 6, 7};
     IBatchReader batchReader = new FakedBatchReader(timestamps);
     Node leafNode = new LeafNode(batchReader);
-
-    Assert.assertTrue(leafNode.hasNextTimeColumn());
-    TimeColumn timeColumn = leafNode.nextTimeColumn();
-    for (long timestamp : timestamps) {
-      Assert.assertEquals(timestamp, timeColumn.currentTime());
-      timeColumn.next();
+    while (leafNode.hasNext()) {
+      Assert.assertEquals(timestamps[index++], leafNode.next());
     }
-    Assert.assertFalse(leafNode.hasNextTimeColumn());
   }
 
   @Test
@@ -74,13 +70,9 @@ public class NodeTest {
     int index = 0;
     Node orNode = new OrNode(new LeafNode(new FakedBatchReader(left)),
         new LeafNode(new FakedBatchReader(right)));
-    while (orNode.hasNextTimeColumn()) {
-      TimeColumn timeSeries = orNode.nextTimeColumn();
-      while (timeSeries.hasCurrent()) {
-        long value = timeSeries.currentTime();
-        timeSeries.next();
-        Assert.assertEquals(ret[index++], value);
-      }
+    while (orNode.hasNext()) {
+      long value = orNode.next();
+      Assert.assertEquals(ret[index++], value);
     }
     Assert.assertEquals(ret.length, index);
   }
@@ -98,13 +90,9 @@ public class NodeTest {
     int index = 0;
     Node andNode = new AndNode(new LeafNode(new FakedBatchReader(left)),
         new LeafNode(new FakedBatchReader(right)));
-    while (andNode.hasNextTimeColumn()) {
-      TimeColumn timeSeries = andNode.nextTimeColumn();
-      while (timeSeries.hasCurrent()) {
-        long value = timeSeries.currentTime();
-        timeSeries.next();
-        Assert.assertEquals(ret[index++], value);
-      }
+    while (andNode.hasNext()) {
+      long value = andNode.next();
+      Assert.assertEquals(ret[index++], value);
     }
     Assert.assertEquals(ret.length, index);
   }

Reply via email to