JackieTien97 commented on a change in pull request #818: [IOTDB-482] Vectorized
TimeGenerator
URL: https://github.com/apache/incubator-iotdb/pull/818#discussion_r380169711
##########
File path:
tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/timegenerator/node/OrNode.java
##########
@@ -19,80 +19,119 @@
package org.apache.iotdb.tsfile.read.query.timegenerator.node;
import java.io.IOException;
+import org.apache.iotdb.tsfile.read.common.TimeColumn;
public class OrNode implements Node {
private Node leftChild;
private Node rightChild;
- private boolean hasCachedLeftValue;
- private long cachedLeftValue;
- private boolean hasCachedRightValue;
- private long cachedRightValue;
+ private TimeColumn leftTimes;
+ private TimeColumn rightTimes;
+
+ private TimeColumn cachedValue;
+ 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()
+ || leftTimes.hasMoreData() || rightTimes.hasMoreData();
}
- private long getLeftValue() throws IOException {
- if (hasCachedLeftValue) {
- hasCachedLeftValue = false;
- return cachedLeftValue;
+ @Override
+ public TimeColumn nextTimeColumn() throws IOException {
+ if (hasCachedValue) {
+ hasCachedValue = false;
+ return cachedValue;
}
- return leftChild.next();
- }
-
- private boolean hasRightValue() throws IOException {
- return hasCachedRightValue || rightChild.hasNext();
- }
+ hasCachedValue = false;
+ cachedValue = new TimeColumn(1000);
- private long getRightValue() throws IOException {
- if (hasCachedRightValue) {
- hasCachedRightValue = false;
- return cachedRightValue;
+ if (!hasLeftValue() && leftChild.hasNextTimeColumn()) {
+ leftTimes = leftChild.nextTimeColumn();
+ }
+ if (!hasRightValue() && rightChild.hasNextTimeColumn()) {
+ rightTimes = rightChild.nextTimeColumn();
}
- return rightChild.next();
- }
- @Override
- public long next() throws IOException {
if (hasLeftValue() && !hasRightValue()) {
- return getLeftValue();
+ return leftTimes;
} else if (!hasLeftValue() && hasRightValue()) {
- return getRightValue();
- } else if (hasLeftValue() && hasRightValue()) {
- long leftValue = getLeftValue();
- long rightValue = getRightValue();
+ return rightTimes;
+ }
+
+ long stopBatchTime = getStopBatchTime();
+
+ while (hasLeftValue() && hasRightValue()) {
+ long leftValue = leftTimes.currentTime();
+ long rightValue = rightTimes.currentTime();
+
if (leftValue < rightValue) {
- hasCachedRightValue = true;
- cachedRightValue = rightValue;
- return leftValue;
+ hasCachedValue = true;
+ cachedValue.add(leftValue);
+ leftTimes.next();
+ if (!leftTimes.hasMoreData() && leftChild.hasNextTimeColumn()) {
+ leftTimes = leftChild.nextTimeColumn();
+ }
} else if (leftValue > rightValue) {
- hasCachedLeftValue = true;
- cachedLeftValue = leftValue;
- return rightValue;
+ hasCachedValue = true;
+ cachedValue.add(rightValue);
+ rightTimes.next();
+ if (!rightTimes.hasMoreData() && rightChild.hasNextTimeColumn()) {
+ rightTimes = rightChild.nextTimeColumn();
+ }
} else {
- return leftValue;
+ hasCachedValue = true;
+ cachedValue.add(leftValue);
+ leftTimes.next();
+ rightTimes.next();
+ if (!leftTimes.hasMoreData() && leftChild.hasNextTimeColumn()) {
+ leftTimes = leftChild.nextTimeColumn();
+ }
+ if (!rightTimes.hasMoreData() && rightChild.hasNextTimeColumn()) {
+ rightTimes = rightChild.nextTimeColumn();
+ }
+ }
+
+ if (leftValue > stopBatchTime && rightValue > stopBatchTime) {
+ break;
}
}
- return -1;
+ hasCachedValue = false;
+ return cachedValue;
+ }
+
+ private long getStopBatchTime() {
+ long rMax = Long.MAX_VALUE;
+ long lMax = Long.MAX_VALUE;
+ if (leftTimes.hasMoreData()) {
+ lMax = leftTimes.getLastTime();
+ }
+ if (rightTimes.hasMoreData()) {
+ rMax = rightTimes.getLastTime();
+ }
+ return rMax > lMax ? lMax : rMax;
Review comment:
use Math.max()
----------------------------------------------------------------
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