This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch TyImproveGroupBy in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 5be02e43370b11572333ff008c3253c7e99a7fcd Author: JackieTien97 <[email protected]> AuthorDate: Fri Jul 17 12:23:58 2020 +0800 improve group by --- .../query/dataset/groupby/LocalGroupByExecutor.java | 19 +++++++++++++++---- .../apache/iotdb/tsfile/read/common/BatchData.java | 13 +++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java index 3fe555d..3ccd596 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java +++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java @@ -42,12 +42,16 @@ import java.util.Set; public class LocalGroupByExecutor implements GroupByExecutor { - private IAggregateReader reader; + private final IAggregateReader reader; private BatchData preCachedData; // Aggregate result buffer of this path - private List<AggregateResult> results = new ArrayList<>(); - private TimeRange timeRange; + private final List<AggregateResult> results = new ArrayList<>(); + private final TimeRange timeRange; + + // used for resetting the batch data to the last index + private int lastReadCurArrayIndex; + private int lastReadCurListIndex; private QueryDataSource queryDataSource; @@ -62,6 +66,8 @@ public class LocalGroupByExecutor implements GroupByExecutor { timeFilter, null, fileFilter); this.preCachedData = null; timeRange = new TimeRange(Long.MIN_VALUE, Long.MAX_VALUE); + lastReadCurArrayIndex = 0; + lastReadCurListIndex = 0; } public boolean isEmpty() { @@ -103,7 +109,7 @@ public class LocalGroupByExecutor implements GroupByExecutor { continue; } // lazy reset batch data for calculation - batchData.resetBatchData(); + batchData.resetBatchData(lastReadCurArrayIndex, lastReadCurListIndex); // skip points that cannot be calculated while (batchData.hasCurrent() && batchData.currentTime() < curStartTime) { batchData.next(); @@ -112,6 +118,8 @@ public class LocalGroupByExecutor implements GroupByExecutor { result.updateResultFromPageData(batchData, curEndTime); } } + lastReadCurArrayIndex = batchData.getReadCurArrayIndex(); + lastReadCurListIndex = batchData.getReadCurListIndex(); // can calc for next interval if (batchData.getMaxTimestamp() >= curEndTime) { preCachedData = batchData; @@ -228,6 +236,9 @@ public class LocalGroupByExecutor implements GroupByExecutor { return true; } + // reset the last position to zero + lastReadCurArrayIndex = 0; + lastReadCurListIndex = 0; calcFromBatch(batchData, curStartTime, curEndTime); // judge whether the calculation finished diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java index a893c1b..b4d6053 100644 --- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java +++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/BatchData.java @@ -580,4 +580,17 @@ public class BatchData implements Serializable { this.readCurArrayIndex = 0; this.readCurListIndex = 0; } + + public void resetBatchData(int readCurArrayIndex, int readCurListIndex) { + this.readCurArrayIndex = readCurArrayIndex; + this.readCurListIndex = readCurListIndex; + } + + public int getReadCurListIndex() { + return readCurListIndex; + } + + public int getReadCurArrayIndex() { + return readCurArrayIndex; + } }
