This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch fix_memtable_scan_bug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 9a85e2c51e2a0e592d33b15df746aab9d2032658 Author: HTHou <[email protected]> AuthorDate: Thu Jan 4 12:25:19 2024 +0800 Fix aligned timeseries query error after delete some data in memtable --- .../IoTDBAlignedSeriesQueryWithDeletionIT.java | 28 ++++++++++++++++++++++ .../memtable/AlignedWritableMemChunk.java | 2 +- .../db/utils/datastructure/AlignedTVList.java | 6 +++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedSeriesQueryWithDeletionIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedSeriesQueryWithDeletionIT.java index 4e22ff973fe..2242398103f 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedSeriesQueryWithDeletionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedSeriesQueryWithDeletionIT.java @@ -126,4 +126,32 @@ public class IoTDBAlignedSeriesQueryWithDeletionIT { fail(e.getMessage()); } } + + @Test + public void selectPartialDeletedColumns() { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "insert into root.sg1.factory0.d1.group1(time, s_lat, s_son)" + + " aligned values (10,3.3,4.4),(20,13.3,14.4),(30,23.3,24.4),(40,43.3,44.4);"); + statement.execute( + "insert into root.sg1.factory0.d1.group1(time, s_lat, s_son, s_boolean)" + + " aligned values (10,3.3,4.4, true),(20,13.3,14.4, false),(30,23.3,24.4, true),(40,43.3,44.4, true);"); + ResultSet resultSet = statement.executeQuery("select * from root.sg1.factory0.d1.group1;"); + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + assertEquals(4, cnt); + statement.execute("delete from root.sg1.factory0.d1.group1.* where time < 30;"); + resultSet = statement.executeQuery("select * from root.sg1.factory0.d1.group1;"); + cnt = 0; + while (resultSet.next()) { + cnt++; + } + assertEquals(2, cnt); + } catch (SQLException e) { + fail(e.getMessage()); + } + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java index f3837b10a16..efacc8afc15 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java @@ -349,7 +349,7 @@ public class AlignedWritableMemChunk implements IWritableMemChunk { int nextRowIndex = sortedRowIndex + 1; while (nextRowIndex < list.rowCount() && rowBitMap != null - && rowBitMap.isMarked(nextRowIndex)) { + && rowBitMap.isMarked(list.getValueIndex(nextRowIndex))) { nextRowIndex++; } if (nextRowIndex != list.rowCount() && time == list.getTime(nextRowIndex)) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java index 4eaf2466498..1a1e3b33624 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java @@ -915,11 +915,13 @@ public abstract class AlignedTVList extends TVList { // time column for (int sortedRowIndex = 0; sortedRowIndex < rowCount; sortedRowIndex++) { // skip empty row - if (rowBitMap != null && rowBitMap.isMarked(sortedRowIndex)) { + if (rowBitMap != null && rowBitMap.isMarked(getValueIndex(sortedRowIndex))) { continue; } int nextRowIndex = sortedRowIndex + 1; - while (nextRowIndex < rowCount && rowBitMap != null && rowBitMap.isMarked(nextRowIndex)) { + while (nextRowIndex < rowCount + && rowBitMap != null + && rowBitMap.isMarked(getValueIndex(nextRowIndex))) { nextRowIndex++; } if (nextRowIndex == rowCount || getTime(sortedRowIndex) != getTime(nextRowIndex)) {
