rdblue commented on code in PR #6090: URL: https://github.com/apache/iceberg/pull/6090#discussion_r1053490603
########## core/src/test/java/org/apache/iceberg/TestRemoveSnapshots.java: ########## @@ -1515,4 +1594,63 @@ private RemoveSnapshots removeSnapshots(Table table) { RemoveSnapshots removeSnapshots = (RemoveSnapshots) table.expireSnapshots(); return (RemoveSnapshots) removeSnapshots.withIncrementalCleanup(incrementalCleanup); } + + private StatisticsFile writeStatsFileForCurrentSnapshot(Table table, File statsLocation) + throws IOException { + StatisticsFile statisticsFile; + try (PuffinWriter puffinWriter = Puffin.write(Files.localOutput(statsLocation)).build()) { + long snapshotId = table.currentSnapshot().snapshotId(); + long snapshotSequenceNumber = table.currentSnapshot().sequenceNumber(); + puffinWriter.add( + new Blob( + "some-blob-type", + ImmutableList.of(1), + snapshotId, + snapshotSequenceNumber, + ByteBuffer.wrap("blob content".getBytes(StandardCharsets.UTF_8)))); + puffinWriter.finish(); + statisticsFile = + new GenericStatisticsFile( + snapshotId, + statsLocation.toString(), + puffinWriter.fileSize(), + puffinWriter.footerSize(), + puffinWriter.writtenBlobsMetadata().stream() + .map(GenericBlobMetadata::from) + .collect(ImmutableList.toImmutableList())); + } + + commitStats(table, statisticsFile); + return statisticsFile; + } + + private StatisticsFile reuseStatsForCurrentSnapshot(Table table, StatisticsFile statisticsFile) { + StatisticsFile newStatisticsFile = + new GenericStatisticsFile( + table.currentSnapshot().snapshotId(), + statisticsFile.path(), + statisticsFile.fileSizeInBytes(), + statisticsFile.fileFooterSizeInBytes(), + statisticsFile.blobMetadata()); + commitStats(table, newStatisticsFile); + return newStatisticsFile; + } + + private void commitStats(Table table, StatisticsFile statisticsFile) { + Transaction transaction = table.newTransaction(); + transaction + .updateStatistics() + .setStatistics(statisticsFile.snapshotId(), statisticsFile) + .commit(); + transaction.commitTransaction(); + } + + private File statsFileLocation(Table table) throws URISyntaxException { Review Comment: This should not use `File` or `URI`. Please use `table.ops().metadataFileLocation(...)` instead. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org