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


The following commit(s) were added to refs/heads/UserDefineTime-TsFile by this 
push:
     new 786d47e0942 sfy
786d47e0942 is described below

commit 786d47e0942ebf28c16cbcf5d0d1a07ab3e73edd
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jan 26 18:16:05 2026 +0800

    sfy
---
 .../fetcher/TableHeaderSchemaValidator.java        | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

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 adc99807210..14a5e1cb06d 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
@@ -676,16 +676,27 @@ public class TableHeaderSchemaValidator {
   }
 
   private void addColumnSchema(final List<ColumnSchema> columnSchemas, final 
TsTable tsTable) {
-    long timeColumnCount = 0;
+    // check if the time column has been specified
+    long timeColumnCount =
+        columnSchemas.stream()
+            .filter(
+                columnDefinition ->
+                    columnDefinition.getColumnCategory() == 
TsTableColumnCategory.TIME)
+            .count();
+    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));
+    }
+
     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(
@@ -698,13 +709,6 @@ 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(

Reply via email to