This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch iotdb_2249 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit e03033b06670241950b6ef485abc9400f05934eb Author: HTHou <[email protected]> AuthorDate: Tue Jan 4 15:24:49 2022 +0800 [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted --- .../db/integration/aligned/IoTDBDeletionIT.java | 31 ++++++++++++++++++++++ .../db/utils/datastructure/AlignedTVList.java | 20 +++++++------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java index 2e245c6..38444a7 100644 --- a/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java +++ b/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBDeletionIT.java @@ -420,6 +420,37 @@ public class IoTDBDeletionIT { } } + @Test + public void testInsertDuplicatedTimeThenDel() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + statement.execute( + "CREATE ALIGNED TIMESERIES root.lz.dev.GPS(latitude FLOAT encoding=PLAIN compressor=SNAPPY, longitude FLOAT encoding=PLAIN compressor=SNAPPY)"); + statement.execute( + "insert into root.lz.dev.GPS(time, latitude, longitude) aligned values(9,3.2,9.8)"); + statement.execute("insert into root.lz.dev.GPS(time, latitude) aligned values(11,4.5)"); + statement.execute("insert into root.lz.dev.GPS(time, longitude) aligned values(11,6.7)"); + + try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) { + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + Assert.assertEquals(2, cnt); + } + + statement.execute("delete from root.lz.dev.GPS.latitude"); + + try (ResultSet resultSet = statement.executeQuery("select * from root.lz.dev.GPS")) { + int cnt = 0; + while (resultSet.next()) { + cnt++; + } + Assert.assertEquals(2, cnt); + } + } + } + private static void prepareSeries() { String sq = null; try (Connection connection = EnvFactory.getEnv().getConnection(); diff --git a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java index 6f42171..47519b5 100644 --- a/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java +++ b/server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java @@ -172,21 +172,19 @@ public class AlignedTVList extends TVList { if (valueIndex >= size) { throw new ArrayIndexOutOfBoundsException(valueIndex); } - int arrayIndex = valueIndex / ARRAY_SIZE; - int elementIndex = valueIndex % ARRAY_SIZE; TsPrimitiveType[] vector = new TsPrimitiveType[values.size()]; for (int columnIndex = 0; columnIndex < values.size(); columnIndex++) { List<Object> columnValues = values.get(columnIndex); - if (validIndexesForTimeDuplicatedRows == null - && (columnValues == null - || bitMaps != null - && bitMaps.get(columnIndex) != null - && isValueMarked(valueIndex, columnIndex))) { - continue; - } + int validValueIndex; if (validIndexesForTimeDuplicatedRows != null) { - arrayIndex = validIndexesForTimeDuplicatedRows[columnIndex] / ARRAY_SIZE; - elementIndex = validIndexesForTimeDuplicatedRows[columnIndex] % ARRAY_SIZE; + validValueIndex = validIndexesForTimeDuplicatedRows[columnIndex]; + } else { + validValueIndex = valueIndex; + } + int arrayIndex = validValueIndex / ARRAY_SIZE; + int elementIndex = validValueIndex % ARRAY_SIZE; + if (columnValues == null || isValueMarked(validValueIndex, columnIndex)) { + continue; } switch (dataTypes.get(columnIndex)) { case TEXT:
