From 188e21859d7502211cdbfda008037be8687fd5c1 Mon Sep 17 00:00:00 2001 From: shuwenwei Date: Wed, 3 Sep 2025 18:54:58 +0800 Subject: [PATCH] Page time range set in TVListIterator is not processed --- .../iotdb/db/utils/datastructure/TVList.java | 18 ++++++++++++++++++ .../memtable/AlignedTVListIteratorTest.java | 14 ++++++++++---- .../memtable/NonAlignedTVListIteratorTest.java | 11 +++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java index c88968d6ffa00..e37fdec551e0d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java @@ -813,6 +813,9 @@ public TsBlock nextBatch() { case BOOLEAN: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) @@ -831,6 +834,9 @@ && isTimeSatisfied(time)) { case DATE: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) @@ -849,6 +855,9 @@ && isTimeSatisfied(time)) { case TIMESTAMP: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) @@ -866,6 +875,9 @@ && isTimeSatisfied(time)) { case FLOAT: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) @@ -885,6 +897,9 @@ && isTimeSatisfied(time)) { case DOUBLE: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) @@ -906,6 +921,9 @@ && isTimeSatisfied(time)) { case STRING: while (index < rows && builder.getPositionCount() < maxNumberOfPointsInPage) { long time = getTime(getScanOrderIndex(index)); + if (isCurrentTimeExceedTimeRange(time)) { + break; + } if (!isNullValue(getValueIndex(getScanOrderIndex(index))) && !isPointDeleted(time, deletionList, deleteCursor, scanOrder) && isLatestPoint(index, time) diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java index 59e58182f6f84..758e0869f2cc9 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedTVListIteratorTest.java @@ -618,11 +618,15 @@ private void testAligned( List> pageStatisticsList = chunk.getTimeStatisticsList(); int count = 0; long offset = paginationController.getCurOffset(); + if (!scanOrder.isAscending()) { + Collections.reverse(pageStatisticsList); + } for (Statistics statistics : pageStatisticsList) { - if (statistics.getStartTime() <= statistics.getEndTime()) { - memPointIterator.setCurrentPageTimeRange( - new TimeRange(statistics.getStartTime(), statistics.getEndTime())); - } + TimeRange currentTimeRange = + (statistics.getStartTime() <= statistics.getEndTime()) + ? new TimeRange(statistics.getStartTime(), statistics.getEndTime()) + : null; + memPointIterator.setCurrentPageTimeRange(currentTimeRange); while (memPointIterator.hasNextBatch()) { TsBlock tsBlock = memPointIterator.nextBatch(); for (int i = 0; i < tsBlock.getPositionCount(); i++) { @@ -635,6 +639,8 @@ private void testAligned( count++; } long currentTimestamp = tsBlock.getTimeByIndex(i); + Assert.assertTrue( + currentTimeRange == null || currentTimeRange.contains(currentTimestamp)); Long int64Value = tsBlock.getColumn(0).isNull(i) ? null : tsBlock.getColumn(0).getLong(i); Boolean boolValue = tsBlock.getColumn(1).isNull(i) ? null : tsBlock.getColumn(1).getBoolean(i); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java index a984eaada1f9b..c22dcbb6b0f44 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/memtable/NonAlignedTVListIteratorTest.java @@ -497,9 +497,15 @@ private void testNonAligned( List> pageStatisticsList = chunk.getPageStatisticsList(); int count = 0; long offset = paginationController.getCurOffset(); + if (!scanOrder.isAscending()) { + Collections.reverse(pageStatisticsList); + } for (Statistics statistics : pageStatisticsList) { - memPointIterator.setCurrentPageTimeRange( - new TimeRange(statistics.getStartTime(), statistics.getEndTime())); + TimeRange currentTimeRange = + (statistics.getStartTime() <= statistics.getEndTime()) + ? new TimeRange(statistics.getStartTime(), statistics.getEndTime()) + : null; + memPointIterator.setCurrentPageTimeRange(currentTimeRange); while (memPointIterator.hasNextBatch()) { TsBlock tsBlock = memPointIterator.nextBatch(); for (int i = 0; i < tsBlock.getPositionCount(); i++) { @@ -512,6 +518,7 @@ private void testNonAligned( count++; } long currentTimestamp = tsBlock.getTimeByIndex(i); + Assert.assertTrue(currentTimeRange.contains(currentTimestamp)); long value = tsBlock.getColumn(0).getLong(i); Assert.assertEquals(currentTimestamp, value); if (globalTimeFilter != null) {