dramaticlly commented on code in PR #19044:
URL: https://github.com/apache/iceberg/pull/19044#discussion_r4645850684
##########
spark/v4.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteTablePathsAction.java:
##########
@@ -1542,6 +1542,99 @@ public void testStatisticsFileSourcePath() throws
IOException {
.hasNoOtherFiles();
}
+ @TestTemplate
+ void incrementalRewriteSkipsStatisticsFilesOfStartVersion() throws
IOException {
+ String sourceTableLocation = newTableLocation();
+ Map<String, String> properties =
+ ImmutableMap.of(TableProperties.FORMAT_VERSION,
String.valueOf(formatVersion));
+ String tableName = String.format("v%stblwithstartstats", formatVersion);
+ Table sourceTable =
+ createMetastoreTable(sourceTableLocation, properties, "default",
tableName, 1, "c1");
+ actions().computeTableStats(sourceTable).execute();
+ actions().computePartitionStats(sourceTable).execute();
+ sourceTable.refresh();
+ String startVersion =
fileName(currentMetadata(sourceTable).metadataFileLocation());
+
+ sql("insert into hive.default.%s values (1, 'AAAAAAAAAA', 'AAAA')",
tableName);
+ sourceTable.refresh();
+
+ RewriteTablePath.Result result =
+ actions()
+ .rewriteTablePath(sourceTable)
+ .rewriteLocationPrefix(sourceTableLocation, targetTableLocation())
+ .startVersion(startVersion)
+ .execute();
+
+ assertThat(result)
+ .hasVersionFiles(1)
+ .hasManifestLists(1)
+ .hasManifests(1)
+ .hasContentFiles(1)
+ .hasNoOtherFiles();
+ }
+
+ @TestTemplate
+ void incrementalRewriteIncludesNewStatisticsFilesOfExistingSnapshot() throws
IOException {
+ String sourceTableLocation = newTableLocation();
+ Map<String, String> properties =
+ ImmutableMap.of(TableProperties.FORMAT_VERSION,
String.valueOf(formatVersion));
+ String tableName = String.format("v%stblwithnewstats", formatVersion);
+ Table sourceTable =
+ createMetastoreTable(sourceTableLocation, properties, "default",
tableName, 1, "c1");
+ String startVersion =
fileName(currentMetadata(sourceTable).metadataFileLocation());
+
+ actions().computeTableStats(sourceTable).execute();
+ actions().computePartitionStats(sourceTable).execute();
+ sourceTable.refresh();
+
+ RewriteTablePath.Result result =
+ actions()
+ .rewriteTablePath(sourceTable)
+ .rewriteLocationPrefix(sourceTableLocation, targetTableLocation())
+ .startVersion(startVersion)
+ .execute();
+
+ assertThat(result)
+ .hasVersionFiles(2)
+ .hasStatisticsFiles(1)
+ .hasPartitionStatisticsFiles(1)
+ .hasNoOtherFiles();
+ }
+
+ @TestTemplate
+ void rewriteSkipsStatisticsFilesOfExpiredSnapshots() throws IOException {
+ String sourceTableLocation = newTableLocation();
+ Map<String, String> properties =
+ ImmutableMap.of(TableProperties.FORMAT_VERSION,
String.valueOf(formatVersion));
+ String tableName = String.format("v%stblwithexpiredstats", formatVersion);
+ Table sourceTable =
+ createMetastoreTable(sourceTableLocation, properties, "default",
tableName, 1, "c1");
+ actions().computeTableStats(sourceTable).execute();
+ actions().computePartitionStats(sourceTable).execute();
+
+ sql("insert into hive.default.%s values (1, 'AAAAAAAAAA', 'AAAA')",
tableName);
+ sourceTable.refresh();
+ actions()
+ .expireSnapshots(sourceTable)
+ .retainLast(1)
+ .expireOlderThan(sourceTable.currentSnapshot().timestampMillis())
+ .execute();
+ sourceTable.refresh();
+
+ RewriteTablePath.Result result =
+ actions()
+ .rewriteTablePath(sourceTable)
+ .rewriteLocationPrefix(sourceTableLocation, targetTableLocation())
+ .execute();
+
+ assertThat(result)
+ .hasVersionFiles(6)
+ .hasManifestLists(1)
+ .hasManifests(2)
+ .hasContentFiles(2)
+ .hasNoOtherFiles();
Review Comment:
added rewriteSkipsReplacedStatisticsFiles below which compute stats twice of
a given snapshot, ensure replication only copy the latest one.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]