private static Collection<PartitionStats> mergeStats(
      Queue<PartitionMap<PartitionStats>> statsByManifest, Map<Integer, PartitionSpec> specs) {
    PartitionMap<PartitionStats> statsMap = PartitionMap.create(specs);

    for (PartitionMap<PartitionStats> stats : statsByManifest) {
      stats.forEach(
          (key, value) ->
              statsMap.merge(
                  key,
                  value,
                  (existingEntry, newEntry) -> {
                    existingEntry.appendStats(newEntry);
                    return existingEntry;
                  }));
    }

    return statsMap.values();
  }
Sorts the {@link PartitionStats} based on the partition data.

@param stats collection of {@link PartitionStats} which needs to be sorted.
@param partitionType unified partition schema.
@return the list of {@link PartitionStats}
iceberg/patched-iceberg-core/src/main/java/org/apache/iceberg/PartitionStatsUtil.java