mxm commented on code in PR #19044:
URL: https://github.com/apache/iceberg/pull/19044#discussion_r4641574868


##########
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:
   Could we add a test that recomputes the table statistics of one snapshot? 
The expiry test covers only deleted files.



##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteTablePathSparkAction.java:
##########
@@ -449,13 +451,28 @@ private Set<Pair<String, String>> rewriteVersionFile(
         Pair.of(
             stagingPath,
             RewriteTablePathUtil.newPath(versionFilePath, sourcePrefix, 
targetPrefix)));
+    return result;
+  }
 
-    // include statistics files in copy plan
+  private Set<Pair<String, String>> statisticsFilesCopyPlan(
+      TableMetadata startMetadata, TableMetadata endMetadata) {
+    TableMetadata newEndMetadata =
+        RewriteTablePathUtil.replacePaths(endMetadata, sourcePrefix, 
targetPrefix);

Review Comment:
   Do we need to call `replacePaths` again here? `rewriteVersionFile` already 
runs it for the end metadata.



##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/RewriteTablePathSparkAction.java:
##########
@@ -449,13 +451,28 @@ private Set<Pair<String, String>> rewriteVersionFile(
         Pair.of(
             stagingPath,
             RewriteTablePathUtil.newPath(versionFilePath, sourcePrefix, 
targetPrefix)));
+    return result;
+  }
 
-    // include statistics files in copy plan
+  private Set<Pair<String, String>> statisticsFilesCopyPlan(

Review Comment:
   NIT: `statisticsFilesCopyPlan` is easy to mix up with `statsFileCopyPlan`. 
Should we name it to `endVersionStatisticsCopyPlan`?



-- 
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]

Reply via email to