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

jt2594838 pushed a commit to branch add_flat_device
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 344cd9641f81d0300e122eeb14e6b5fa8e5d1c00
Author: Tian Jiang <[email protected]>
AuthorDate: Mon Sep 7 09:53:28 2026 +0800

    tmp
---
 .../relational/it/db/it/IoTDBLoadTsFileIT.java     | 89 ++++++++++++++++++++++
 1 file changed, 89 insertions(+)

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 c4444c4bf55..4f33ff23a41 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
@@ -560,6 +560,95 @@ public class IoTDBLoadTsFileIT {
     }
   }
 
+  @Test
+  public void testLoadIntoFlatDeviceTablePreservesTagColumns() throws 
Exception {
+    // Regression coverage: flat_device LOAD converts the source TsFile to 
Tablet batches, so TAG
+    // values must survive conversion together with rows that share the same 
timestamp.
+    final String database = "flat_device_load";
+    final String table = "sensor";
+    final List<IMeasurementSchema> schemas =
+        Arrays.asList(
+            new MeasurementSchema("tag_a", TSDataType.STRING),
+            new MeasurementSchema("tag_b", TSDataType.STRING),
+            new MeasurementSchema("value_1", TSDataType.INT64),
+            new MeasurementSchema("value_2", TSDataType.DOUBLE));
+    final List<String> columnNames = Arrays.asList("tag_a", "tag_b", 
"value_1", "value_2");
+    final List<TSDataType> dataTypes =
+        Arrays.asList(TSDataType.STRING, TSDataType.STRING, TSDataType.INT64, 
TSDataType.DOUBLE);
+    final List<ColumnCategory> columnCategories =
+        Arrays.asList(
+            ColumnCategory.TAG, ColumnCategory.TAG, ColumnCategory.FIELD, 
ColumnCategory.FIELD);
+    final File file = new File(tmpDir, "flat-device-load.tsfile");
+
+    try (final TsFileWriter tsFileWriter = new TsFileWriter(file)) {
+      tsFileWriter.registerTableSchema(new TableSchema(table, schemas, 
columnCategories));
+      final Tablet tablet = new Tablet(table, columnNames, dataTypes, 
columnCategories, 4);
+      addFlatDeviceLoadRow(tablet, 1, "a", "1", 10L, 1.0D);
+      addFlatDeviceLoadRow(tablet, 1, "a", "2", 20L, 2.0D);
+      addFlatDeviceLoadRow(tablet, 1, "b", "1", 30L, 3.0D);
+      addFlatDeviceLoadRow(tablet, 2, "b", "1", 40L, 4.0D);
+      tsFileWriter.writeTable(tablet);
+    }
+
+    try (final Connection connection =
+            EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+        final Statement statement = connection.createStatement()) {
+      statement.execute("CREATE DATABASE " + database);
+      statement.execute("USE " + database);
+      statement.execute(
+          "CREATE TABLE "
+              + table
+              + " (tag_a STRING TAG, tag_b STRING TAG, value_1 INT64 FIELD, "
+              + "value_2 DOUBLE FIELD) WITH (flat_device=true)");
+
+      try (final ResultSet resultSet = statement.executeQuery("SHOW CREATE 
TABLE " + table)) {
+        Assert.assertTrue(resultSet.next());
+        Assert.assertTrue(resultSet.getString(2).contains("flat_device=true"));
+      }
+
+      statement.execute(
+          String.format("LOAD '%s' WITH ('database'='%s')", 
file.getAbsolutePath(), database));
+
+      try (final ResultSet resultSet =
+          statement.executeQuery(
+              "SELECT time, tag_a, tag_b, value_1, value_2 FROM "
+                  + table
+                  + " ORDER BY time, tag_a, tag_b")) {
+        final List<String> actualRows = new ArrayList<>();
+        while (resultSet.next()) {
+          actualRows.add(
+              resultSet.getLong(1)
+                  + ","
+                  + resultSet.getString(2)
+                  + ","
+                  + resultSet.getString(3)
+                  + ","
+                  + resultSet.getLong(4)
+                  + ","
+                  + resultSet.getDouble(5));
+        }
+        Assert.assertEquals(
+            Arrays.asList("1,a,1,10,1.0", "1,a,2,20,2.0", "1,b,1,30,3.0", 
"2,b,1,40,4.0"),
+            actualRows);
+      }
+    }
+  }
+
+  private static void addFlatDeviceLoadRow(
+      final Tablet tablet,
+      final long time,
+      final String tagA,
+      final String tagB,
+      final long value1,
+      final double value2) {
+    final int row = tablet.getRowSize();
+    tablet.addTimestamp(row, time);
+    tablet.addValue("tag_a", row, tagA);
+    tablet.addValue("tag_b", row, tagB);
+    tablet.addValue("value_1", row, value1);
+    tablet.addValue("value_2", row, value2);
+  }
+
   private static class SchemaConfig {
     private static final String DATABASE_0 = "root";
     private static final String TABLE_0 = "test";

Reply via email to