@VisibleForTesting
  static PartitionStatisticsFile writePartitionStatsFile(
      Table table, long snapshotId, Schema dataSchema, Iterator<PartitionStats> records) {
    OutputFile outputFile = newPartitionStatsFile(table, snapshotId);

    try (DataWriter<StructLike> writer = dataWriter(dataSchema, outputFile)) {
      records.forEachRemaining(writer::write);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }

    return ImmutableGenericPartitionStatisticsFile.builder()
        .snapshotId(snapshotId)
        .path(outputFile.location())
        .fileSizeInBytes(outputFile.toInputFile().getLength())
        .build();
  }
Computes and writes the {@link PartitionStatisticsFile} for a given table and branch.

@param table The {@link Table} for which the partition statistics is computed.
@param branch A branch information to select the required snapshot.
@return {@link PartitionStatisticsFile} for the given branch.
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/data/PartitionStatsHandler.java