This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch rc/2.0.8 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit fe588714866d7e716590842d413b1acf3eedbf1d Author: alpass163 <[email protected]> AuthorDate: Tue Feb 3 18:10:03 2026 +0800 fix the bug that insert null into the time column #17150 --- .../relational/it/db/it/IoTDBInsertTableIT.java | 36 ++++++++++++++++++++++ .../plan/relational/sql/parser/AstBuilder.java | 2 ++ 2 files changed, 38 insertions(+) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java index b079d022e79..c223761cd2a 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBInsertTableIT.java @@ -354,6 +354,42 @@ public class IoTDBInsertTableIT { } } + @Test + public void testInsertNullIntoTime() { + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + statement.execute("use \"test\""); + statement.execute( + "CREATE TABLE insert_null (region string tag, time_test timestamp time, s1 int64 field)"); + + try { + statement.execute("insert into insert_null values('SZ', null, 1)"); + fail("expected exception"); + } catch (SQLException e) { + assertEquals("701: Timestamp cannot be null", e.getMessage()); + } + + try { + statement.execute("insert into insert_null(region, time_test, s1) values('SZ', null, 1)"); + fail("expected exception"); + } catch (SQLException e) { + assertEquals("701: Timestamp cannot be null", e.getMessage()); + } + + try { + statement.execute( + "insert into insert_null(region, time_test, s1) values('SZ', 2, 2),('HK', null ,3)"); + fail("expected exception"); + } catch (SQLException e) { + assertEquals("701: Timestamp cannot be null", e.getMessage()); + } + + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + @Test public void testInsertNaN() throws SQLException { try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java index 1ad212cf560..83105468a02 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java @@ -992,6 +992,8 @@ public class AstBuilder extends RelationalSqlBaseVisitor<Node> { Expression timeExpression = expressions.get(timeColumnIndex); if (timeExpression instanceof LongLiteral) { timestamp = ((LongLiteral) timeExpression).getParsedValue(); + } else if (timeExpression instanceof NullLiteral) { + throw new SemanticException("Timestamp cannot be null"); } else { timestamp = parseDateTimeFormat(
