This is an automated email from the ASF dual-hosted git repository. hui pushed a commit to branch lmh/aggrOpRefactor in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 64da2532e43c4477806a68a2fb2e0c20844c408e Author: Minghui Liu <[email protected]> AuthorDate: Thu Jul 7 17:19:19 2022 +0800 bug fix: distinguish skipToTimeRangePoints & skipOutOfTimeRangePoints --- .../db/mpp/execution/operator/AggregationUtil.java | 30 +++++++++++++++++++++- .../source/SeriesAggregationScanOperator.java | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/AggregationUtil.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/AggregationUtil.java index f05cb17ab7..24c5d87a01 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/AggregationUtil.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/AggregationUtil.java @@ -90,6 +90,34 @@ public class AggregationUtil { } // skip points that cannot be calculated + public static TsBlock skipToTimeRangePoints( + TsBlock tsBlock, TimeRange targetTimeRange, boolean ascending) { + TimeColumn timeColumn = tsBlock.getTimeColumn(); + long targetTime = ascending ? targetTimeRange.getMin() : targetTimeRange.getMax(); + int left = 0, right = timeColumn.getPositionCount() - 1, mid; + // if ascending, find the first greater than or equal to targetTime + // else, find the first less than or equal to targetTime + while (left < right) { + mid = (left + right) >> 1; + if (timeColumn.getLongWithoutCheck(mid) < targetTime) { + if (ascending) { + left = mid + 1; + } else { + right = mid; + } + } else if (timeColumn.getLongWithoutCheck(mid) > targetTime) { + if (ascending) { + right = mid; + } else { + left = mid + 1; + } + } else if (timeColumn.getLongWithoutCheck(mid) == targetTime) { + return tsBlock.subTsBlock(mid); + } + } + return tsBlock.subTsBlock(left); + } + public static TsBlock skipOutOfTimeRangePoints( TsBlock tsBlock, TimeRange curTimeRange, boolean ascending) { TimeColumn timeColumn = tsBlock.getTimeColumn(); @@ -112,7 +140,7 @@ public class AggregationUtil { left = mid + 1; } } else if (timeColumn.getLongWithoutCheck(mid) == targetTime) { - return tsBlock.subTsBlock(mid); + return tsBlock.subTsBlock(mid + 1); } } return tsBlock.subTsBlock(left); diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesAggregationScanOperator.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesAggregationScanOperator.java index 1f0e11485c..db5f1b30a0 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesAggregationScanOperator.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesAggregationScanOperator.java @@ -45,7 +45,7 @@ import java.util.Set; import static org.apache.iotdb.db.mpp.execution.operator.AggregationUtil.appendAggregationResult; import static org.apache.iotdb.db.mpp.execution.operator.AggregationUtil.initTimeRangeIterator; import static org.apache.iotdb.db.mpp.execution.operator.AggregationUtil.isEndCalc; -import static org.apache.iotdb.db.mpp.execution.operator.AggregationUtil.skipOutOfTimeRangePoints; +import static org.apache.iotdb.db.mpp.execution.operator.AggregationUtil.skipToTimeRangePoints; /** * This operator is responsible to do the aggregation calculation for one series based on global @@ -248,7 +248,7 @@ public class SeriesAggregationScanOperator implements DataSourceOperator { // skip points that cannot be calculated if ((ascending && tsBlock.getStartTime() < curTimeRange.getMin()) || (!ascending && tsBlock.getStartTime() > curTimeRange.getMax())) { - tsBlock = skipOutOfTimeRangePoints(tsBlock, curTimeRange, ascending); + tsBlock = skipToTimeRangePoints(tsBlock, curTimeRange, ascending); } int lastReadRowIndex = 0;
