Skip to content

Commit 100c5a3

Browse files
authored
Fix window partiton across two TsBlock bugs (apache#16809)
1 parent 0431d5a commit 100c5a3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/window/TableWindowOperator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ private LinkedList<PartitionExecutor> partition(TsBlock tsBlock) {
294294
partitionExecutors.addLast(partitionExecutor);
295295

296296
partitionStartInCurrentBlock = partitionEndInCurrentBlock;
297+
// Reset cross-TsBlock tracking after partition completion
298+
startIndexInFirstBlock = -1;
297299
} else {
298300
// Last partition of TsBlock
299301
// The beginning of next TsBlock may have rows in this partition

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/process/window/TableWindowOperatorTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,57 @@ public void testMixedPartition() {
192192
}
193193
}
194194

195+
@Test
196+
public void testMixedPartition2() {
197+
long[][] timeArray =
198+
new long[][] {
199+
{1, 2, 3},
200+
{4, 5},
201+
{6},
202+
};
203+
String[][] deviceIdArray =
204+
new String[][] {
205+
{"d1", "d1", "d2"},
206+
{"d2", "d3"},
207+
{"d3"},
208+
};
209+
int[][] valueArray =
210+
new int[][] {
211+
{1, 2, 3},
212+
{4, 5},
213+
{6},
214+
};
215+
216+
long[] expectColumn1 = new long[] {1, 2, 3, 4, 5, 6};
217+
String[] expectColumn2 = new String[] {"d1", "d1", "d2", "d2", "d3", "d3"};
218+
int[] expectColumn4 = new int[] {1, 2, 3, 4, 5, 6};
219+
long[] expectColumn5 = new long[] {1, 2, 1, 2, 1, 2};
220+
221+
int count = 0;
222+
try (TableWindowOperator windowOperator =
223+
genWindowOperator(timeArray, deviceIdArray, valueArray)) {
224+
ListenableFuture<?> listenableFuture = windowOperator.isBlocked();
225+
listenableFuture.get();
226+
while (!windowOperator.isFinished() && windowOperator.hasNext()) {
227+
TsBlock tsBlock = windowOperator.next();
228+
if (tsBlock != null && !tsBlock.isEmpty()) {
229+
for (int i = 0, size = tsBlock.getPositionCount(); i < size; i++, count++) {
230+
assertEquals(expectColumn1[count], tsBlock.getColumn(0).getLong(i));
231+
assertEquals(
232+
expectColumn2[count],
233+
tsBlock.getColumn(1).getBinary(i).getStringValue(TSFileConfig.STRING_CHARSET));
234+
assertEquals(expectColumn4[count], tsBlock.getColumn(2).getInt(i));
235+
assertEquals(expectColumn5[count], tsBlock.getColumn(3).getLong(i));
236+
}
237+
}
238+
}
239+
assertEquals(6, count);
240+
} catch (Exception e) {
241+
e.printStackTrace();
242+
fail(e.getMessage());
243+
}
244+
}
245+
195246
static class ChildOperator implements Operator {
196247
private int index;
197248

0 commit comments

Comments
 (0)