Skip to content

Commit 07def73

Browse files
committed
update
1 parent a348f69 commit 07def73

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
125125
}
126126
}
127127

128-
// Get timestamps
128+
// Get timestamps - always copy to ensure immutability
129129
final long[] times = statement.getTimes();
130130
final int rowSize = statement.getRowCount();
131131
final long[] timestamps;
132132
if (times != null && times.length >= rowSize && rowSize > 0) {
133-
timestamps = times;
133+
timestamps = new long[rowSize];
134+
System.arraycopy(times, 0, timestamps, 0, rowSize);
134135
} else {
135136
LOGGER.warn(
136137
"Times array is null or too small. times.length={}, rowSize={}, deviceId={}",
@@ -153,8 +154,11 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
153154
}
154155
}
155156

156-
// Get bitMaps
157-
final BitMap[] bitMaps = statement.getBitMaps();
157+
// Get bitMaps - copy array to ensure immutability
158+
final BitMap[] originalBitMaps = statement.getBitMaps();
159+
final BitMap[] bitMaps = originalBitMaps != null
160+
? Arrays.copyOf(originalBitMaps, originalBitMaps.length)
161+
: null;
158162

159163
// Create Tablet using the full constructor
160164
// Tablet(String tableName, List<IMeasurementSchema> schemas, List<ColumnCategory>
@@ -176,24 +180,49 @@ public static Tablet convertStatementToTablet(final InsertTabletStatement statem
176180
/**
177181
* Convert a single column value from Statement format to Tablet format. Statement uses primitive
178182
* 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.
179185
*
180186
* @param columnValue column value from Statement (primitive array)
181187
* @param dataType data type of the column
182-
* @return column value in Tablet format
188+
* @return column value in Tablet format (copied array)
183189
*/
184190
private static Object convertStatementColumnToTablet(
185191
final Object columnValue, final TSDataType dataType) {
186192

187193
if (TSDataType.DATE.equals(dataType)) {
188194
final int[] values = (int[]) columnValue;
189-
final LocalDate[] localDateValue = new LocalDate[values.length];
190-
for (int i = 0; i < values.length; i++) {
191-
localDateValue[i] = DateUtils.parseIntToLocalDate(values[i]);
195+
// Copy the array first to ensure immutability
196+
final int[] copiedValues = Arrays.copyOf(values, values.length);
197+
final LocalDate[] localDateValue = new LocalDate[copiedValues.length];
198+
for (int i = 0; i < copiedValues.length; i++) {
199+
localDateValue[i] = DateUtils.parseIntToLocalDate(copiedValues[i]);
192200
}
193-
194201
return localDateValue;
195202
}
196-
// For primitive arrays (boolean[], int[], long[], float[], double[]), return as-is
203+
204+
// For primitive arrays, always copy to ensure immutability
205+
if (columnValue == null) {
206+
return null;
207+
}
208+
209+
if (columnValue instanceof boolean[]) {
210+
return Arrays.copyOf((boolean[]) columnValue, ((boolean[]) columnValue).length);
211+
} else if (columnValue instanceof int[]) {
212+
return Arrays.copyOf((int[]) columnValue, ((int[]) columnValue).length);
213+
} else if (columnValue instanceof long[]) {
214+
return Arrays.copyOf((long[]) columnValue, ((long[]) columnValue).length);
215+
} else if (columnValue instanceof float[]) {
216+
return Arrays.copyOf((float[]) columnValue, ((float[]) columnValue).length);
217+
} else if (columnValue instanceof double[]) {
218+
return Arrays.copyOf((double[]) columnValue, ((double[]) columnValue).length);
219+
} else if (columnValue instanceof Binary[]) {
220+
// For Binary arrays, create a new array and copy references
221+
final Binary[] original = (Binary[]) columnValue;
222+
return Arrays.copyOf(original, original.length);
223+
}
224+
225+
// For other types, return as-is (should not happen for standard types)
197226
return columnValue;
198227
}
199228

0 commit comments

Comments
 (0)