You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/03/18 08:14:22 UTC
[GitHub] [iotdb] neuyilan commented on a change in pull request #2859: Optimize cluster query
neuyilan commented on a change in pull request #2859:
URL: https://github.com/apache/iotdb/pull/2859#discussion_r596602238
##########
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:
will this cause an infinite loop? maybe we should break the while loop when find one result[i]?
----------------------------------------------------------------
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