From 65776cfa54139de65f482845cde546d5aeaeb6c7 Mon Sep 17 00:00:00 2001 From: alanchuang22-dev <2584829494@qq.com> Date: Tue, 3 Nov 2026 12:45:23 +0800 Subject: [PATCH 1/2] fix: change condition in `hasRemainingGapInPreviousGroup()` --- .../operator/process/gapfill/AbstractGapFillOperator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java index fd9a281b5f49b..473d840ae1c56 100644 --- a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java +++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java @@ -224,7 +224,7 @@ public boolean hasNext() throws Exception { } private boolean hasRemainingGapInPreviousGroup() { - return lastGroupKey != null && currentTime < endTime; + return lastGroupKey != null && currentTime <= endTime; } @Override From 7330aef57b03655a0d579b464c45a2d5642e015e Mon Sep 17 00:00:00 2001 From: alanchuang22-dev <2584829494@qq.com> Date: Tue, 3 Nov 2026 16:49:45 +0800 Subject: [PATCH 2/2] fix: add `timeIteratorExhausted` as label --- .../gapfill/AbstractGapFillOperator.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java index 473d840ae1c56..4089e4bbca637 100644 --- a/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java +++ b/iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java @@ -59,6 +59,7 @@ abstract class AbstractGapFillOperator implements ProcessOperator { private final long endTime; protected long currentTime; + private boolean timeIteratorExhausted; private SortKey lastGroupKey = null; AbstractGapFillOperator( @@ -140,6 +141,14 @@ public TsBlock next() throws Exception { private void resetTimeIterator() { currentTime = startTime; + timeIteratorExhausted = false; + } + + private void advanceTimeIterator() { + long previousTime = currentTime; + nextTime(); + // Saturation leaves no later timestamp to mark the consumed window across next() calls. + timeIteratorExhausted |= currentTime <= previousTime; } private void writeCurrentRow(TsBlock block, int rowIndex) { @@ -153,7 +162,7 @@ private void writeCurrentRow(TsBlock block, int rowIndex) { columnBuilder.write(column, rowIndex); } } - nextTime(); + advanceTimeIterator(); } private void fillGaps(TsBlock block, int rowIndex, long currentEndTime) { @@ -162,13 +171,10 @@ private void fillGaps(TsBlock block, int rowIndex, long currentEndTime) { private void fillGaps( TsBlock block, int rowIndex, long currentEndTime, boolean endTimeInclusive) { - while (currentTime < currentEndTime || (endTimeInclusive && currentTime == currentEndTime)) { - long previousTime = currentTime; + while (!timeIteratorExhausted + && (currentTime < currentEndTime || (endTimeInclusive && currentTime == currentEndTime))) { gapFillRow(currentTime, block, rowIndex); - nextTime(); - if (currentTime <= previousTime) { - break; - } + advanceTimeIterator(); } } @@ -224,7 +230,7 @@ public boolean hasNext() throws Exception { } private boolean hasRemainingGapInPreviousGroup() { - return lastGroupKey != null && currentTime <= endTime; + return lastGroupKey != null && !timeIteratorExhausted && currentTime <= endTime; } @Override