Skip to content

Commit bdf8543

Browse files
committed
Fix the issue "Only the target component should be written, not all of them".
1 parent 87a4da5 commit bdf8543

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/ResourceByPathUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,12 @@ public AbstractAlignedTimeSeriesMetadata generateTimeSeriesMetadata(
268268
modified = (modified || alignedChunkMetadata.isModified());
269269
TSDataType targetDataType = alignedFullPath.getSchemaList().get(index).getType();
270270
if (targetDataType.equals(TSDataType.STRING)
271-
&& (alignedChunkMetadata.getValueChunkMetadataList().stream()
272-
.filter(iChunkMetadata -> iChunkMetadata.getDataType() != targetDataType)
273-
.count()
274-
> 0)) {
271+
&& ((alignedChunkMetadata.getValueChunkMetadataList().get(index) != null)
272+
&& (alignedChunkMetadata.getValueChunkMetadataList().get(index).getDataType()
273+
!= targetDataType))) {
275274
// create new statistics object via new data type, and merge statistics information
276-
alignedChunkMetadata =
277-
SchemaUtils.rewriteAlignedChunkMetadataStatistics(alignedChunkMetadata, targetDataType);
275+
SchemaUtils.rewriteAlignedChunkMetadataStatistics(
276+
alignedChunkMetadata, index, targetDataType);
278277
alignedChunkMetadata.setModified(true);
279278
}
280279
if (!useFakeStatistics) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.tsfile.enums.TSDataType;
2828
import org.apache.tsfile.file.metadata.AbstractAlignedChunkMetadata;
2929
import org.apache.tsfile.file.metadata.AbstractAlignedTimeSeriesMetadata;
30-
import org.apache.tsfile.file.metadata.AlignedChunkMetadata;
3130
import org.apache.tsfile.file.metadata.ChunkMetadata;
3231
import org.apache.tsfile.file.metadata.IChunkMetadata;
3332
import org.apache.tsfile.file.metadata.TimeseriesMetadata;
@@ -41,7 +40,6 @@
4140
import org.slf4j.LoggerFactory;
4241

4342
import java.nio.charset.StandardCharsets;
44-
import java.util.ArrayList;
4543
import java.util.Arrays;
4644
import java.util.Collections;
4745
import java.util.HashMap;
@@ -400,25 +398,20 @@ public static void changeAlignedMetadataModified(
400398
}
401399
}
402400

403-
public static AbstractAlignedChunkMetadata rewriteAlignedChunkMetadataStatistics(
404-
AbstractAlignedChunkMetadata alignedChunkMetadata, TSDataType targetDataType) {
405-
List<IChunkMetadata> newValueChunkMetadataList = new ArrayList<>();
406-
for (IChunkMetadata valueChunkMetadata : alignedChunkMetadata.getValueChunkMetadataList()) {
407-
if (valueChunkMetadata != null
408-
&& targetDataType.isCompatible(valueChunkMetadata.getDataType())) {
409-
Statistics<?> statistics = Statistics.getStatsByType(targetDataType);
410-
statistics = getNewStatistics(valueChunkMetadata, targetDataType, statistics);
411-
412-
ChunkMetadata newChunkMetadata = (ChunkMetadata) valueChunkMetadata;
413-
newChunkMetadata.setTsDataType(targetDataType);
414-
newChunkMetadata.setStatistics(statistics);
415-
newValueChunkMetadataList.add(newChunkMetadata);
416-
} else {
417-
newValueChunkMetadataList.add(null);
418-
}
401+
public static void rewriteAlignedChunkMetadataStatistics(
402+
AbstractAlignedChunkMetadata alignedChunkMetadata, int index, TSDataType targetDataType) {
403+
IChunkMetadata valueChunkMetadata = alignedChunkMetadata.getValueChunkMetadataList().get(index);
404+
if (valueChunkMetadata != null
405+
&& targetDataType.isCompatible(valueChunkMetadata.getDataType())) {
406+
Statistics<?> statistics = Statistics.getStatsByType(targetDataType);
407+
statistics = getNewStatistics(valueChunkMetadata, targetDataType, statistics);
408+
409+
ChunkMetadata newChunkMetadata = (ChunkMetadata) valueChunkMetadata;
410+
newChunkMetadata.setTsDataType(targetDataType);
411+
newChunkMetadata.setStatistics(statistics);
412+
} else {
413+
alignedChunkMetadata.getValueChunkMetadataList().set(index, null);
419414
}
420-
return new AlignedChunkMetadata(
421-
alignedChunkMetadata.getTimeChunkMetadata(), newValueChunkMetadataList);
422415
}
423416

424417
public static void rewriteNonAlignedChunkMetadataStatistics(

0 commit comments

Comments
 (0)