@Override
  public void endMeasurement(int subTaskId) throws IOException {
    List<TimeValuePair> dataOfCurrentSeries = dataOfCurrentSeriesArr[subTaskId];
    if (dataOfCurrentSeries.isEmpty()) {
      super.endMeasurement(subTaskId);
      return;
    }
    // remove duplicate timestamp and sort
    dataOfCurrentSeries.sort(Comparator.comparingLong(TimeValuePair::getTimestamp));
    TimeValuePair previousTimeValuePair = dataOfCurrentSeries.get(0);
    for (TimeValuePair timeValuePair : dataOfCurrentSeries) {
      if (timeValuePair.getTimestamp() == previousTimeValuePair.getTimestamp()) {
        // merge to previous TimeValuePair if is aligned series
        mergeTimeValuePair(timeValuePair, previousTimeValuePair);
        continue;
      }
      writeToChunkWriter(previousTimeValuePair, subTaskId);
      previousTimeValuePair = timeValuePair;
    }
    // write last time value pair
    writeToChunkWriter(previousTimeValuePair, subTaskId);

    dataOfCurrentSeriesArr[subTaskId] = null;
    super.endMeasurement(subTaskId);
  }
Used for fixing files which contains internal unsorted data
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/compaction/execute/utils/writer/RepairUnsortedFileCompactionWriter.java