Skip to content

Commit 6ea3052

Browse files
authored
Fix: Adding the time column is prohibited. (#17215)
1 parent 8cfb49d commit 6ea3052

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBTableWithDefinedTimeIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,26 @@ public void testCreateView() {
227227
fail(e.getMessage());
228228
}
229229
}
230+
231+
@Test
232+
public void testAddTimeColumn() {
233+
try (final Connection connection =
234+
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
235+
final Statement statement = connection.createStatement()) {
236+
statement.execute("use " + TABLE_DATABASE);
237+
238+
try {
239+
statement.execute(
240+
"create table table_time(device string tag, s1 int32 field, record_time timestamp time)");
241+
statement.execute("alter table table_time add column d_datetime timestamp time");
242+
fail("Add the TIME column should not be supported");
243+
} catch (SQLException e) {
244+
assertEquals("701: Adding TIME column is not supported.", e.getMessage());
245+
}
246+
247+
} catch (SQLException e) {
248+
e.printStackTrace();
249+
fail(e.getMessage());
250+
}
251+
}
230252
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ protected IConfigTask visitAddColumn(final AddColumn node, final MPPQueryContext
722722
context.getSession().getUserName(), new QualifiedObjectName(database, tableName), context);
723723

724724
final ColumnDefinition definition = node.getColumn();
725+
if (definition.getColumnCategory() == TsTableColumnCategory.TIME) {
726+
throw new SemanticException("Adding TIME column is not supported.");
727+
}
725728
return new AlterTableAddColumnTask(
726729
database,
727730
tableName,

0 commit comments

Comments
 (0)