public void sortAndDeduplicateByDevIdTimestamp() {
    if (tablet == null || tablet.getRowSize() < 1) {
      return;
    }

    final HashMap<IDeviceID, List<Pair<Integer, Integer>>> deviceIDToIndexMap = new HashMap<>();
    final long[] timestamps = tablet.getTimestamps();

    IDeviceID lastDevice = tablet.getDeviceID(0);
    long previousTimestamp = tablet.getTimestamp(0);
    int lasIndex = 0;
    for (int i = 1, size = tablet.getRowSize(); i < size; ++i) {
      final IDeviceID deviceID = tablet.getDeviceID(i);
      final long currentTimestamp = timestamps[i];
      final int deviceComparison = deviceID.compareTo(lastDevice);
      if (deviceComparison == 0) {
        if (previousTimestamp == currentTimestamp) {
          isDeDuplicated = false;
          continue;
        }
        if (previousTimestamp > currentTimestamp) {
          isSorted = false;
        }
        previousTimestamp = currentTimestamp;
        continue;
      }
      if (deviceComparison < 0) {
        isSorted = false;
      }

      final List<Pair<Integer, Integer>> list =
          deviceIDToIndexMap.computeIfAbsent(lastDevice, k -> new ArrayList<>());

      if (!list.isEmpty()) {
        isSorted = false;
      }
      list.add(new Pair<>(lasIndex, i));
      lastDevice = deviceID;
      lasIndex = i;
      previousTimestamp = currentTimestamp;
    }

    final List<Pair<Integer, Integer>> list =
        deviceIDToIndexMap.computeIfAbsent(lastDevice, k -> new ArrayList<>());
    if (!list.isEmpty()) {
      isSorted = false;
    }
    list.add(new Pair<>(lasIndex, tablet.getRowSize()));

    if (isSorted && isDeDuplicated) {
      return;
    }

    initIndexSize = 0;
    deDuplicatedSize = 0;
    index = new Integer[tablet.getRowSize()];
    deDuplicatedIndex = new int[tablet.getRowSize()];
    deviceIDToIndexMap.entrySet().stream()
        .sorted(Map.Entry.comparingByKey())
        .forEach(
            entry -> {
              int i = initIndexSize;
              for (Pair<Integer, Integer> pair : entry.getValue()) {
                for (int j = pair.left; j < pair.right; j++) {
                  index[i++] = j;
                }
              }
              if (!isSorted) {
                sortTimestamps(initIndexSize, i);
                deDuplicateTimestamps(initIndexSize, i);
                initIndexSize = i;
                return;
              }

              if (!isDeDuplicated) {
                deDuplicateTimestamps(initIndexSize, i);
              }
              initIndexSize = i;
            });

    sortAndDeduplicateValuesAndBitMapsWithTimestamp();
  }
For the sorting and deduplication needs of the table model tablet, it is done according to the
{@link IDeviceID}. For sorting, it is necessary to sort the {@link IDeviceID} first, and then
sort by time. Deduplication is to remove the same timestamp in the same {@link IDeviceID}, and
the same timestamp in different {@link IDeviceID} will not be processed.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/util/sorter/PipeTableModelTabletEventSorter.java