This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch fix_delete_alignd_text_npe_11 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 8f3960f02fca25f3d92e7cbd891c185b7a6cd73a Author: HTHou <[email protected]> AuthorDate: Thu May 18 15:02:06 2023 +0800 [IOTDB-5896] Fix delete aligned TEXT data in TVList NPE --- .../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); } }
