This is an automated email from the ASF dual-hosted git repository. jiangtian pushed a commit to branch fix_del_after_update in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d6e0b5c214dc1b3c8057f705db940d75ff6bf50b Author: Tian Jiang <[email protected]> AuthorDate: Tue Nov 19 18:51:48 2024 +0800 fix that the row deletion mark is mistakenly use --- .../org/apache/iotdb/db/it/IoTDBDeletionIT.java | 31 ++++++++++++++++++++++ .../db/utils/datastructure/AlignedTVList.java | 21 ++++++++------- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDeletionIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDeletionIT.java index 76810eeddf0..0137a8c97cd 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDeletionIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDeletionIT.java @@ -437,6 +437,37 @@ public class IoTDBDeletionIT { } } + @Test + public void testDelAfterUpdate() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.ln12.d1 (status int32)"); + statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(1, 1)"); + statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(2, 2)"); + statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(3, 3)"); + statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(2, 2)"); + + try (ResultSet resultSet = statement.executeQuery("select status from root.ln12.d1")) { + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + Assert.assertEquals(3, cnt); + } + + statement.execute("DELETE FROM root.ln12.d1.* WHERE time <= 2"); + + try (ResultSet resultSet = statement.executeQuery("select status from root.ln12.d1")) { + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + Assert.assertEquals(1, cnt); + } + } + } + private static void prepareSeries() { try (Connection connection = EnvFactory.getEnv().getConnection(); Statement statement = connection.createStatement()) { 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 2a9402aa00d..f0a645bf3ec 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 @@ -493,30 +493,28 @@ public abstract class AlignedTVList extends TVList { /** * Get whether value is null at the given position in AlignedTvList. * - * @param rowIndex value index inside this column + * @param unsortedRowIndex value index inside this column * @param columnIndex index of the column * @return boolean */ - public boolean isNullValue(int rowIndex, int columnIndex) { - if (rowIndex >= rowCount) { + public boolean isNullValue(int unsortedRowIndex, int columnIndex) { + if (unsortedRowIndex >= rowCount) { return false; } - if (allValueColDeletedMap != null && allValueColDeletedMap.isMarked(rowIndex)) { - return true; - } - if (isTimeDeleted(rowIndex)) { + if (allValueColDeletedMap != null && allValueColDeletedMap.isMarked(unsortedRowIndex)) { return true; } + if (values.get(columnIndex) == null) { return true; } if (bitMaps == null || bitMaps.get(columnIndex) == null - || bitMaps.get(columnIndex).get(rowIndex / ARRAY_SIZE) == null) { + || bitMaps.get(columnIndex).get(unsortedRowIndex / ARRAY_SIZE) == null) { return false; } - int arrayIndex = rowIndex / ARRAY_SIZE; - int elementIndex = rowIndex % ARRAY_SIZE; + int arrayIndex = unsortedRowIndex / ARRAY_SIZE; + int elementIndex = unsortedRowIndex % ARRAY_SIZE; List<BitMap> columnBitMaps = bitMaps.get(columnIndex); return columnBitMaps.get(arrayIndex).isMarked(elementIndex); } @@ -1424,6 +1422,9 @@ public abstract class AlignedTVList extends TVList { return timeColDeletedMap; } + /** + * @param rowIndex should be the sorted index. + */ public boolean isTimeDeleted(int rowIndex) { int bitmapIndex = getValueIndex(rowIndex); if (timeColDeletedMap == null || timeColDeletedMap.getSize() <= bitmapIndex) {
