This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch force_ci/UserDefinedTime
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/force_ci/UserDefinedTime by 
this push:
     new 7ab8ee61ef3 Load: Fixed the extra time column of user defined time 
(#17113)
7ab8ee61ef3 is described below

commit 7ab8ee61ef393ded4a5dcd2d6edf74b06cb30757
Author: Caideyipi <[email protected]>
AuthorDate: Thu Jan 29 19:32:03 2026 +0800

    Load: Fixed the extra time column of user defined time (#17113)
---
 .../relational/it/db/it/IoTDBLoadTsFileIT.java     | 40 +++++++++++++++++++++-
 .../fetcher/TableHeaderSchemaValidator.java        |  2 +-
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadTsFileIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadTsFileIT.java
index d14c0896816..a58e0633b74 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadTsFileIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBLoadTsFileIT.java
@@ -298,6 +298,7 @@ public class IoTDBLoadTsFileIT {
   public void testLoadWithTimeColumn() throws Exception {
     final int lineCount = 10000;
 
+    // from: 1 time
     List<Pair<MeasurementSchema, MeasurementSchema>> measurementSchemas =
         generateMeasurementSchemasWithTime(1, "time");
     List<ColumnCategory> columnCategories =
@@ -313,63 +314,84 @@ public class IoTDBLoadTsFileIT {
       generator.generateData(SchemaConfig.TABLE_0, lineCount, 
PARTITION_INTERVAL / 10_000);
     }
 
+    // to: 1 time
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
+    // to: empty
     testWithTimeColumn(lineCount, null, null, file);
 
     measurementSchemas = generateMeasurementSchemasWithTime(2, "time");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 2);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
+
+    // to: 2 time
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: 0 time
     measurementSchemas = generateMeasurementSchemasWithTime(-1, "time");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), -1);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: 2 time1
     measurementSchemas = generateMeasurementSchemasWithTime(2, "time1");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 2);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // from: 2 time1
     file = new File(tmpDir, "2-0-0-0.tsfile");
     try (final TsFileTableGenerator generator = new 
TsFileTableGenerator(file)) {
       generator.registerTable(SchemaConfig.TABLE_0, new 
ArrayList<>(schemaList1), columnCategories);
       generator.generateData(SchemaConfig.TABLE_0, lineCount, 
PARTITION_INTERVAL / 10_000);
     }
 
+    // to: 2 time
     measurementSchemas = generateMeasurementSchemasWithTime(2, "time");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 2);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: 1 time
     measurementSchemas = generateMeasurementSchemasWithTime(1, "time1");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 1);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: empty
     testWithTimeColumn(lineCount, null, null, file);
 
+    // to: 0 time
     measurementSchemas = generateMeasurementSchemasWithTime(-1, "time");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), -1);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // from: 0 time
     file = new File(tmpDir, "3-0-0-0.tsfile");
     try (final TsFileTableGenerator generator = new 
TsFileTableGenerator(file)) {
       generator.registerTable(SchemaConfig.TABLE_0, new 
ArrayList<>(schemaList1), columnCategories);
       generator.generateData(SchemaConfig.TABLE_0, lineCount, 
PARTITION_INTERVAL / 10_000);
     }
 
+    // to: 2 time
     measurementSchemas = generateMeasurementSchemasWithTime(2, "time");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 2);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: 1 time1
     measurementSchemas = generateMeasurementSchemasWithTime(1, "time1");
     columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), 1);
     schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
     testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
 
+    // to: 0 time
+    measurementSchemas = generateMeasurementSchemasWithTime(-1, "time");
+    columnCategories = generateTabletColumnCategory(0, 
measurementSchemas.size(), -1);
+    schemaList1 = measurementSchemas.stream().map(pair -> 
pair.left).collect(Collectors.toList());
+    testWithTimeColumn(lineCount, schemaList1, columnCategories, file);
+
+    // to: empty
     testWithTimeColumn(lineCount, null, null, file);
   }
 
@@ -384,8 +406,10 @@ public class IoTDBLoadTsFileIT {
         final Statement statement = connection.createStatement()) {
       statement.execute(String.format("create database if not exists %s", 
SchemaConfig.DATABASE_0));
       statement.execute(String.format("use %s", SchemaConfig.DATABASE_0));
+      ResultSet resultSetOld = null;
       if (Objects.nonNull(schemaList1)) {
         statement.execute(convert2TableSQL(SchemaConfig.TABLE_0, schemaList1, 
columnCategories));
+        resultSetOld = statement.executeQuery("desc " + SchemaConfig.TABLE_0);
       }
       statement.execute(
           String.format(
@@ -404,6 +428,20 @@ public class IoTDBLoadTsFileIT {
         Assert.assertFalse(resultSet.next());
       }
 
+      // Time column's difference shall not affect the old column
+      if (Objects.nonNull(resultSetOld)) {
+        try (final ResultSet resultSet = statement.executeQuery("desc " + 
SchemaConfig.TABLE_0)) {
+          while (resultSet.next() && resultSetOld.next()) {
+            Assert.assertEquals(resultSet.getString(1), 
resultSetOld.getString(1));
+            Assert.assertEquals(resultSet.getString(2), 
resultSetOld.getString(2));
+            Assert.assertEquals(resultSet.getString(3), 
resultSetOld.getString(3));
+          }
+          if (resultSet.next() || resultSetOld.next()) {
+            Assert.fail("The table schema has changed after load.");
+          }
+        }
+      }
+
       statement.execute(String.format("drop database %s", 
SchemaConfig.DATABASE_0));
     }
   }
@@ -413,7 +451,7 @@ public class IoTDBLoadTsFileIT {
   }
 
   private List<ColumnCategory> generateTabletColumnCategory(
-      int tagNum, int fieldNum, final int timeIndex) {
+      final int tagNum, final int fieldNum, final int timeIndex) {
     List<ColumnCategory> columnTypes =
         new ArrayList<>(tagNum + fieldNum + (timeIndex >= 0 ? 1 : 0));
     for (int i = 0; i < tagNum; i++) {
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 5eb90feae2e..7f578cef4ae 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
@@ -870,7 +870,7 @@ public class TableHeaderSchemaValidator {
                   
TSFileDescriptor.getInstance().getConfig().getCompressor(dataType)));
           break;
         case TIME:
-          columnSchemaList.add(new TimeColumnSchema(inputColumn.getName(), 
TSDataType.TIMESTAMP));
+          // Do nothing, cause the time column shall never be appended to the 
existing table
           break;
         default:
           throw new IllegalStateException(

Reply via email to