You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2023/05/18 09:53:09 UTC

[iotdb] branch rel/1.1 updated: [IOTDB-5896] Fix delete aligned TEXT data in TVList NPE (#9885)

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

xingtanzjr pushed a commit to branch rel/1.1
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/1.1 by this push:
     new ea9effa80d [IOTDB-5896] Fix delete aligned TEXT data in TVList NPE (#9885)
ea9effa80d is described below

commit ea9effa80d0bbc97936342f55598bd887b8b29eb
Author: Haonan <hh...@outlook.com>
AuthorDate: Thu May 18 17:53:02 2023 +0800

    [IOTDB-5896] Fix delete aligned TEXT data in TVList NPE (#9885)
---
 .../iotdb/db/it/aligned/IoTDBAlignedDataDeletionIT.java | 17 +++++++++++++++++
 .../iotdb/db/utils/datastructure/AlignedTVList.java     |  6 ++++--
 .../iotdb/db/utils/datastructure/VectorTVListTest.java  | 11 +++++++++++
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedDataDeletionIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedDataDeletionIT.java
index fd2cb1a1ba..c83df7ffb0 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedDataDeletionIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBAlignedDataDeletionIT.java
@@ -266,6 +266,23 @@ public class IoTDBAlignedDataDeletionIT {
     cleanData();
   }
 
+  @Test
+  public void testDeleteAfterColumnExtended() throws SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      statement.execute("insert into root.vehicle.d0(time,s0) aligned values (10,310)");
+      statement.execute("insert into root.vehicle.d0(time,s3) aligned values (10,'text')");
+      statement.execute("insert into root.vehicle.d0(time,s4) aligned values (10,true)");
+
+      try {
+        statement.execute("DELETE FROM root.vehicle.d0.s3");
+      } catch (SQLException e) {
+        fail(e.getMessage());
+      }
+    }
+  }
+
   @Test
   public void testFullDeleteWithoutWhereClause() throws SQLException {
     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 dfba829696..bb9b79edd1 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
@@ -516,8 +516,10 @@ public abstract class AlignedTVList extends TVList {
         int arrayIndex = originRowIndex / ARRAY_SIZE;
         int elementIndex = originRowIndex % ARRAY_SIZE;
         if (dataTypes.get(columnIndex) == TSDataType.TEXT) {
-          memoryBinaryChunkSize[columnIndex] -=
-              getBinarySize(((Binary[]) values.get(columnIndex).get(arrayIndex))[elementIndex]);
+          Binary value = ((Binary[]) values.get(columnIndex).get(arrayIndex))[elementIndex];
+          if (value != null) {
+            memoryBinaryChunkSize[columnIndex] -= getBinarySize(value);
+          }
         }
         markNullValue(columnIndex, arrayIndex, elementIndex);
         deletedNumber++;
diff --git a/server/src/test/java/org/apache/iotdb/db/utils/datastructure/VectorTVListTest.java b/server/src/test/java/org/apache/iotdb/db/utils/datastructure/VectorTVListTest.java
index 7f660e73b6..4dbe5cdeee 100644
--- a/server/src/test/java/org/apache/iotdb/db/utils/datastructure/VectorTVListTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/utils/datastructure/VectorTVListTest.java
@@ -269,7 +269,18 @@ public class VectorTVListTest {
     Assert.assertEquals(tvList.memoryBinaryChunkSize.length, 2);
     Assert.assertEquals(tvList.memoryBinaryChunkSize[0], 324);
 
+    tvList.extendColumn(TSDataType.TEXT);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize.length, 3);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize[0], 324);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize[2], 0);
+
+    tvList.delete(4, 6);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize.length, 3);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize[0], 216);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize[2], 0);
+
     tvList.clear();
     Assert.assertEquals(tvList.memoryBinaryChunkSize[0], 0);
+    Assert.assertEquals(tvList.memoryBinaryChunkSize[2], 0);
   }
 }