diff --git a/hadoop-ozone/iceberg/src/test/java/org/apache/hadoop/ozone/iceberg/TestRewriteTablePathOzoneAction.java b/hadoop-ozone/iceberg/src/test/java/org/apache/hadoop/ozone/iceberg/TestRewriteTablePathOzoneAction.java index 8678fe52301e..fb657c981982 100644 --- a/hadoop-ozone/iceberg/src/test/java/org/apache/hadoop/ozone/iceberg/TestRewriteTablePathOzoneAction.java +++ b/hadoop-ozone/iceberg/src/test/java/org/apache/hadoop/ozone/iceberg/TestRewriteTablePathOzoneAction.java @@ -18,6 +18,7 @@ package org.apache.hadoop.ozone.iceberg; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; @@ -33,12 +34,14 @@ import org.apache.iceberg.DataFile; import org.apache.iceberg.DataFiles; import org.apache.iceberg.FileFormat; +import org.apache.iceberg.GenericStatisticsFile; import org.apache.iceberg.HasTableOperations; import org.apache.iceberg.PartitionSpec; import org.apache.iceberg.RewriteTablePathUtil; import org.apache.iceberg.Schema; import org.apache.iceberg.Snapshot; import org.apache.iceberg.StaticTableOperations; +import org.apache.iceberg.StatisticsFile; import org.apache.iceberg.Table; import org.apache.iceberg.TableMetadata; import org.apache.iceberg.TableMetadata.MetadataLogEntry; @@ -188,6 +191,51 @@ void tablePathRewriteForStartAndEndVersionProvided() throws Exception { assertAllInternalPathsRewritten(csvPairs, targetPrefix); } + @Test + void statsFileCopyPlanReturnsEmptySetForEmptyStats() { + Set> copyPlan = + RewriteTablePathOzoneUtils.statsFileCopyPlan(List.of(), List.of()); + + assertTrue(copyPlan.isEmpty()); + } + + @Test + void statsFileCopyPlanRejectsMismatchedStatsCount() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> RewriteTablePathOzoneUtils.statsFileCopyPlan( + List.of(statisticsFile("before-1.stats", 100)), + List.of())); + + assertEquals("Before and after path rewrite, statistic files count should be same", + exception.getMessage()); + } + + @Test + void statsFileCopyPlanRejectsMismatchedStatsFileSize() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> RewriteTablePathOzoneUtils.statsFileCopyPlan( + List.of(statisticsFile("before-1.stats", 100)), + List.of(statisticsFile("after-1.stats", 200)))); + + assertEquals("Before and after path rewrite, statistic files size should be same", + exception.getMessage()); + } + + @Test + void statsFileCopyPlanReturnsBeforeToAfterPathPairs() { + Set> copyPlan = RewriteTablePathOzoneUtils.statsFileCopyPlan( + List.of( + statisticsFile("before-1.stats", 100), + statisticsFile("before-2.stats", 200)), + List.of( + statisticsFile("after-1.stats", 100), + statisticsFile("after-2.stats", 200))); + + assertEquals(Set.of( + Pair.of("before-1.stats", "after-1.stats"), + Pair.of("before-2.stats", "after-2.stats")), copyPlan); + } + /** * For every staged metadata JSON file in the CSV, parses the file and asserts that: * - The table location starts with target @@ -276,4 +324,8 @@ private DataFile dummyDataFile(String dataPath) { .withFormat(FileFormat.PARQUET) .build(); } + + private static StatisticsFile statisticsFile(String path, long fileSizeInBytes) { + return new GenericStatisticsFile(1L, path, fileSizeInBytes, 0L, List.of()); + } }