This is an automated email from the ASF dual-hosted git repository. justinchen pushed a commit to branch UserDefineTime-TsFile in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a580760e1f1cbd0b0b175b41a81307dc9c485879 Author: Caideyipi <[email protected]> AuthorDate: Thu Jan 22 14:29:24 2026 +0800 Update TableHeaderSchemaValidator.java --- .../metadata/fetcher/TableHeaderSchemaValidator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableHeaderSchemaValidator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableHeaderSchemaValidator.java index 846dceeca2d..f1cf4b48987 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableHeaderSchemaValidator.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableHeaderSchemaValidator.java @@ -70,6 +70,7 @@ import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import static org.apache.iotdb.commons.schema.table.TsTable.TIME_COLUMN_NAME; import static org.apache.iotdb.db.queryengine.plan.relational.type.InternalTypeManager.getTSDataType; import static org.apache.iotdb.db.utils.EncodingInferenceUtils.getDefaultEncoding; @@ -673,12 +674,16 @@ public class TableHeaderSchemaValidator { } private void addColumnSchema(final List<ColumnSchema> columnSchemas, final TsTable tsTable) { + long timeColumnCount = 0; for (final ColumnSchema columnSchema : columnSchemas) { TsTableColumnCategory category = columnSchema.getColumnCategory(); if (category == null) { throw new ColumnCreationFailException( "Cannot create column " + columnSchema.getName() + " category is not provided"); } + if (category == TsTableColumnCategory.TIME) { + ++timeColumnCount; + } final String columnName = columnSchema.getName(); if (tsTable.getColumnSchema(columnName) != null) { throw new SemanticException( @@ -691,6 +696,13 @@ public class TableHeaderSchemaValidator { } tsTable.addColumnSchema(generateColumnSchema(category, columnName, dataType, null, null)); } + if (timeColumnCount > 1) { + throw new SemanticException("A table cannot have more than one time column"); + } + if (timeColumnCount == 0) { + // append the time column with default name "time" if user do not specify the time column + tsTable.addColumnSchema(new TimeColumnSchema(TIME_COLUMN_NAME, TSDataType.TIMESTAMP)); + } } public static TsTableColumnSchema generateColumnSchema(
