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

[iotdb] branch iotdb_2249 created (now e03033b)

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

haonan pushed a change to branch iotdb_2249
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at e03033b  [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted

This branch includes the following new commits:

     new e03033b  [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: [IOTDB-2249] Fix query NPE when an aligned column with duplicated time is deleted

Posted by ha...@apache.org.
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 <hh...@outlook.com>
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: