You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/01/04 13:13:54 UTC

[iotdb] branch master updated: [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted (#4702)

This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 99600d2  [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted (#4702)
99600d2 is described below

commit 99600d25d87deedaf5a106c9542879ef895fc9c9
Author: Haonan <hh...@outlook.com>
AuthorDate: Tue Jan 4 21:13:22 2022 +0800

    [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted (#4702)
---
 .../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: