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 38e9193c36b565d6bff8af445d8be79758860d91
Author: Tian Jiang <[email protected]>
AuthorDate: Mon Aug 31 16:02:55 2026 +0800

    tmp
---
 .../dataregion/memtable/AbstractMemTable.java      | 31 ++++++++++++-----
 .../memtable/AlignedWritableMemChunk.java          |  3 +-
 .../db/utils/datastructure/AlignedTVList.java      | 40 ++++++++++++++++++----
 3 files changed, 58 insertions(+), 16 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
index 34a35df64f4..a07f9f724e4 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AbstractMemTable.java
@@ -307,9 +307,12 @@ public abstract class AbstractMemTable implements 
IMemTable {
             schemaList,
             sortColumnCount,
             insertRowNode.isFlatDevice());
-    memChunkGroup.writeRow(insertRowNode.getTime(), writableValues, 
schemaList);
     if (memChunkGroup instanceof AlignedWritableMemChunkGroup 
alignedMemChunkGroup) {
+      alignedMemChunkGroup.writeRow(
+          insertRowNode.getTime(), writableValues, schemaList, 
insertRowNode.getColumnCategories());
       alignedMemChunkGroup.addSortColumnCount(sortColumnCount);
+    } else {
+      memChunkGroup.writeRow(insertRowNode.getTime(), writableValues, 
schemaList);
     }
     int validValueCount = insertRowNode.getValidMemTableMeasurementNumber();
     int pointsInserted =
@@ -530,16 +533,26 @@ public abstract class AbstractMemTable implements 
IMemTable {
       IWritableMemChunkGroup memChunkGroup =
           createAlignedMemChunkGroupIfNotExistAndGet(
               deviceID, schemaList, sortColumnCount, 
insertTabletNode.isFlatDevice());
-      memChunkGroup.writeTablet(
-          insertTabletNode.getTimes(),
-          writableColumns,
-          writableBitMaps,
-          schemaList,
-          splitStart,
-          splitEnd,
-          results);
       if (memChunkGroup instanceof AlignedWritableMemChunkGroup 
alignedMemChunkGroup) {
+        alignedMemChunkGroup.writeTablet(
+            insertTabletNode.getTimes(),
+            writableColumns,
+            writableBitMaps,
+            schemaList,
+            insertTabletNode.getColumnCategories(),
+            splitStart,
+            splitEnd,
+            results);
         alignedMemChunkGroup.addSortColumnCount(sortColumnCount);
+      } else {
+        memChunkGroup.writeTablet(
+            insertTabletNode.getTimes(),
+            writableColumns,
+            writableBitMaps,
+            schemaList,
+            splitStart,
+            splitEnd,
+            results);
       }
       splitStart = splitEnd;
     }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java
index ae701b99317..513dacbab33 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/AlignedWritableMemChunk.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.db.storageengine.dataregion.memtable;
 
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
@@ -53,7 +54,6 @@ import org.apache.tsfile.write.schema.MeasurementSchema;
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -69,6 +69,7 @@ import static 
org.apache.iotdb.db.utils.ModificationUtils.isPointDeleted;
 public class AlignedWritableMemChunk extends AbstractWritableMemChunk {
 
   private Map<String, Integer> measurementIndexMap;
+  private final Map<String, TsTableColumnCategory> measurementCategoryMap;
   private List<TSDataType> dataTypes;
   private final List<IMeasurementSchema> schemaList;
   // Note: Use AbstractWritableMemChunk.workingListForFlush instead of list in 
FlushTask
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
index 16167238230..a45d4783196 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -643,22 +643,50 @@ public abstract class AlignedTVList extends TVList {
   }
 
   public void extendColumn(TSDataType dataType) {
+    insertColumn(values.size(), dataType);
+  }
+
+  /**
+   * Inserts an empty value column at the given logical index.
+   *
+   * <p>Aligned TVLists keep all value-column metadata in parallel arrays. 
Keeping the insertion
+   * here (instead of modifying only {@link #values}) ensures historical rows, 
null bitmaps, and
+   * memory accounting remain aligned when a flat-device TAG is inserted 
before existing fields.
+   */
+  public synchronized void insertColumn(int columnIndex, TSDataType dataType) {
+    if (columnIndex < 0 || columnIndex > values.size()) {
+      throw new IndexOutOfBoundsException(columnIndex);
+    }
     List<Object> columnValue = new ArrayList<>(timestamps.size());
     for (int i = 0; i < timestamps.size(); i++) {
       columnValue.add(null);
     }
     if (bitMaps != null) {
-      bitMaps.add(null);
+      bitMaps.add(columnIndex, null);
     }
-    this.values.add(columnValue);
-    this.dataTypes.add(dataType);
+    this.values.add(columnIndex, columnValue);
+    this.dataTypes.add(columnIndex, dataType);
     refreshArrayMemCostWithoutPrimitiveArrays();
 
     long[] tmpValueChunkRawSize = memoryBinaryChunkSize;
-    memoryBinaryChunkSize = new long[dataTypes.size()];
+    memoryBinaryChunkSize = new long[tmpValueChunkRawSize.length + 1];
+    System.arraycopy(tmpValueChunkRawSize, 0, memoryBinaryChunkSize, 0, 
columnIndex);
+    System.arraycopy(
+        tmpValueChunkRawSize,
+        columnIndex,
+        memoryBinaryChunkSize,
+        columnIndex + 1,
+        tmpValueChunkRawSize.length - columnIndex);
+    int[] tmpMaterializedValueArrayCounts = materializedValueArrayCounts;
+    materializedValueArrayCounts = new 
int[tmpMaterializedValueArrayCounts.length + 1];
+    System.arraycopy(
+        tmpMaterializedValueArrayCounts, 0, materializedValueArrayCounts, 0, 
columnIndex);
     System.arraycopy(
-        tmpValueChunkRawSize, 0, memoryBinaryChunkSize, 0, 
tmpValueChunkRawSize.length);
-    materializedValueArrayCounts = Arrays.copyOf(materializedValueArrayCounts, 
dataTypes.size());
+        tmpMaterializedValueArrayCounts,
+        columnIndex,
+        materializedValueArrayCounts,
+        columnIndex + 1,
+        tmpMaterializedValueArrayCounts.length - columnIndex);
   }
 
   private Object getObjectByValueIndex(int rowIndex, int columnIndex) {

Reply via email to