This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch fix_division_by_zero_when_flush in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit fb33c15846e051b2c707f967be664686c87c632f Author: HTHou <[email protected]> AuthorDate: Mon Mar 10 10:52:25 2025 +0800 Fix division by zero error when flush memtable --- .../it/db/it/IoTDBFlushQueryTableIT.java | 30 +++++++++++++++------- .../db/utils/datastructure/AlignedTVList.java | 9 ++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryTableIT.java index 1ad8427b6f3..85af3ad0ff7 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBFlushQueryTableIT.java @@ -27,7 +27,6 @@ import org.apache.iotdb.itbase.env.BaseEnv; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; @@ -179,22 +178,35 @@ public class IoTDBFlushQueryTableIT { } @Test - @Ignore public void testFlushNotExistGroupNoData() { - try (final Connection connection = EnvFactory.getEnv().getConnection(); + try (final Connection connection = + EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); final Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.noexist.nodatagroup1"); + statement.execute("CREATE DATABASE noexist_nodatagroup1"); try { - statement.execute( - "FLUSH root.noexist.nodatagroup1,root.notExistGroup1,root.notExistGroup2"); + statement.execute("FLUSH noexist_nodatagroup1,notExistGroup1,notExistGroup2"); } catch (final SQLException sqe) { - String expectedMsg = - "322: 322: Database root.notExistGroup1,root.notExistGroup2 does not exist"; - sqe.printStackTrace(); + String expectedMsg = "Database notExistGroup1,notExistGroup2 does not exist"; assertTrue(sqe.getMessage().contains(expectedMsg)); } } catch (Exception e) { fail(e.getMessage()); } } + + @Test + public void testFlushTableAfterDropColumn() { + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + statement.execute("create database db1"); + statement.execute("use db1"); + statement.execute("create table t2(s1 text field, s2 text field)"); + statement.execute("insert into t2(time,s2) values(2,'t1')"); + statement.execute("alter table t2 drop column s2"); + statement.execute("flush"); + statement.execute("insert into t2(time,s1) values(2,'t1')"); + } catch (Exception e) { + fail(e.getMessage()); + } + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java index 5d8a2bfe5ac..23295d0065c 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java @@ -1481,12 +1481,15 @@ public abstract class AlignedTVList extends TVList { if (largestBinaryChunkSize == 0) { return largestPrimitivePointSize; } - int avgPointSizeOfLargestBinaryColumn = - (int) largestBinaryChunkSize / getColumnValueCnt(largestBinaryColumnIndex); + int columnValueCnt = getColumnValueCnt(largestBinaryColumnIndex); + if (columnValueCnt == 0) { + return largestPrimitivePointSize; + } + int avgPointSizeOfLargestBinaryColumn = (int) largestBinaryChunkSize / columnValueCnt; return Math.max(avgPointSizeOfLargestBinaryColumn, largestPrimitivePointSize); } - public int getColumnValueCnt(int columnIndex) { + private int getColumnValueCnt(int columnIndex) { int pointNum = 0; if (bitMaps == null || bitMaps.get(columnIndex) == null) { pointNum = rowCount;
