Skip to content

Commit b9bc692

Browse files
committed
update
1 parent 07def73 commit b9bc692

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/util/TabletStatementConverter.java

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,37 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
9393
final MeasurementSchema[] measurementSchemas = statement.getMeasurementSchemas();
9494
final String[] measurements = statement.getMeasurements();
9595
final TSDataType[] dataTypes = statement.getDataTypes();
96-
final int schemaSize = measurements != null ? measurements.length : 0;
96+
// If measurements and dataTypes are not null, use measurements.length as the standard length
97+
final int originalSchemaSize = measurements != null ? measurements.length : 0;
9798

99+
// Build schemas and track valid column indices (skip null columns)
100+
// measurements and dataTypes being null is standard - skip those columns
98101
final List<IMeasurementSchema> schemas = new ArrayList<>();
99-
for (int i = 0; i < schemaSize; i++) {
100-
if (measurementSchemas != null && measurementSchemas[i] != null) {
101-
schemas.add(measurementSchemas[i]);
102-
} else if (measurements[i] != null && dataTypes[i] != null) {
102+
final List<Integer> validColumnIndices = new ArrayList<>();
103+
for (int i = 0; i < originalSchemaSize; i++) {
104+
if (dataTypes != null && measurements[i] != null && dataTypes[i] != null) {
103105
// Create MeasurementSchema if not present
104106
schemas.add(new MeasurementSchema(measurements[i], dataTypes[i]));
105-
} else {
106-
schemas.add(null);
107+
validColumnIndices.add(i);
107108
}
109+
// Skip null columns - don't add to schemas or validColumnIndices
108110
}
109111

110-
// Get columnTypes (for table model)
112+
final int schemaSize = schemas.size();
113+
114+
// Get columnTypes (for table model) - only for valid columns
111115
final TsTableColumnCategory[] columnCategories = statement.getColumnCategories();
112116
final List<ColumnCategory> tabletColumnTypes = new ArrayList<>();
113117
if (columnCategories != null && columnCategories.length > 0) {
114-
for (int i = 0; i < schemaSize; i++) {
115-
if (columnCategories[i] != null) {
116-
tabletColumnTypes.add(columnCategories[i].toTsFileColumnType());
118+
for (final int validIndex : validColumnIndices) {
119+
if (columnCategories[validIndex] != null) {
120+
tabletColumnTypes.add(columnCategories[validIndex].toTsFileColumnType());
117121
} else {
118122
tabletColumnTypes.add(ColumnCategory.FIELD);
119123
}
120124
}
121125
} else {
122-
// Default to FIELD for all columns if not specified
126+
// Default to FIELD for all valid columns if not specified
123127
for (int i = 0; i < schemaSize; i++) {
124128
tabletColumnTypes.add(ColumnCategory.FIELD);
125129
}
@@ -141,24 +145,34 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
141145
timestamps = new long[0];
142146
}
143147

144-
// Get values - convert Statement columns to Tablet format
148+
// Get values - convert Statement columns to Tablet format, only for valid columns
145149
final Object[] statementColumns = statement.getColumns();
146150
final Object[] tabletValues = new Object[schemaSize];
147151
if (statementColumns != null && statementColumns.length > 0) {
148-
for (int i = 0; i < schemaSize; i++) {
149-
if (statementColumns[i] != null && dataTypes[i] != null) {
150-
tabletValues[i] = convertStatementColumnToTablet(statementColumns[i], dataTypes[i]);
152+
for (int i = 0; i < validColumnIndices.size(); i++) {
153+
final int originalIndex = validColumnIndices.get(i);
154+
if (statementColumns[originalIndex] != null && dataTypes[originalIndex] != null) {
155+
tabletValues[i] =
156+
convertStatementColumnToTablet(
157+
statementColumns[originalIndex], dataTypes[originalIndex]);
151158
} else {
152159
tabletValues[i] = null;
153160
}
154161
}
155162
}
156163

157-
// Get bitMaps - copy array to ensure immutability
164+
// Get bitMaps - copy array to ensure immutability, only for valid columns
158165
final BitMap[] originalBitMaps = statement.getBitMaps();
159-
final BitMap[] bitMaps = originalBitMaps != null
160-
? Arrays.copyOf(originalBitMaps, originalBitMaps.length)
161-
: null;
166+
final BitMap[] bitMaps;
167+
if (originalBitMaps != null && originalBitMaps.length > 0) {
168+
bitMaps = new BitMap[schemaSize];
169+
for (int i = 0; i < validColumnIndices.size(); i++) {
170+
final int originalIndex = validColumnIndices.get(i);
171+
bitMaps[i] = originalBitMaps[originalIndex];
172+
}
173+
} else {
174+
bitMaps = null;
175+
}
162176

163177
// Create Tablet using the full constructor
164178
// Tablet(String tableName, List<IMeasurementSchema> schemas, List<ColumnCategory>
@@ -179,9 +193,9 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
179193

180194
/**
181195
* Convert a single column value from Statement format to Tablet format. Statement uses primitive
182-
* arrays (e.g., int[], long[], float[]), while Tablet may need different format.
183-
* All arrays are copied to ensure immutability - even if the original array is modified,
184-
* the converted array remains unchanged.
196+
* arrays (e.g., int[], long[], float[]), while Tablet may need different format. All arrays are
197+
* copied to ensure immutability - even if the original array is modified, the converted array
198+
* remains unchanged.
185199
*
186200
* @param columnValue column value from Statement (primitive array)
187201
* @param dataType data type of the column

0 commit comments

Comments
 (0)