mukund-thakur commented on code in PR #16421:
URL: https://github.com/apache/iceberg/pull/16421#discussion_r3554953197


##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteTablePathsAction.java:
##########
@@ -426,6 +426,101 @@ public void testPositionDeletesOrc() throws Exception {
     runPositionDeletesTest("orc");
   }
 
+  @TestTemplate
+  public void testRerunWithPositionDeletesReusingStagingLocation() throws 
Exception {
+    assumeThat(formatVersion).isEqualTo(2);
+
+    Table tableWithPosDeletes =
+        createTableWithSnapshots(
+            
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
+            2,
+            Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));
+
+    List<Pair<CharSequence, Long>> deletes =
+        Lists.newArrayList(
+            Pair.of(
+                SnapshotChanges.builderFor(tableWithPosDeletes)
+                    .build()
+                    .addedDataFiles()
+                    .iterator()
+                    .next()
+                    .location(),
+                0L));
+    File file =
+        new File(
+            removePrefix(tableWithPosDeletes.location() + 
"/data/deeply/nested/deletes.parquet"));
+    DeleteFile positionDeletes =
+        FileHelpers.writeDeleteFile(
+                tableWithPosDeletes,
+                
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
+                deletes,
+                formatVersion)
+            .first();
+    tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();
+
+    actions()
+        .rewriteTablePath(tableWithPosDeletes)
+        .stagingLocation(stagingLocation())
+        .rewriteLocationPrefix(tableWithPosDeletes.location(), 
targetTableLocation())
+        .execute();
+

Review Comment:
   nit: should verify the run is success here as well. 



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/actions/TestRewriteTablePathsAction.java:
##########
@@ -426,6 +426,101 @@ public void testPositionDeletesOrc() throws Exception {
     runPositionDeletesTest("orc");
   }
 
+  @TestTemplate
+  public void testRerunWithPositionDeletesReusingStagingLocation() throws 
Exception {
+    assumeThat(formatVersion).isEqualTo(2);
+
+    Table tableWithPosDeletes =
+        createTableWithSnapshots(
+            
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
+            2,
+            Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));
+
+    List<Pair<CharSequence, Long>> deletes =
+        Lists.newArrayList(
+            Pair.of(
+                SnapshotChanges.builderFor(tableWithPosDeletes)
+                    .build()
+                    .addedDataFiles()
+                    .iterator()
+                    .next()
+                    .location(),
+                0L));
+    File file =
+        new File(
+            removePrefix(tableWithPosDeletes.location() + 
"/data/deeply/nested/deletes.parquet"));
+    DeleteFile positionDeletes =
+        FileHelpers.writeDeleteFile(
+                tableWithPosDeletes,
+                
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
+                deletes,
+                formatVersion)
+            .first();
+    tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();
+
+    actions()
+        .rewriteTablePath(tableWithPosDeletes)
+        .stagingLocation(stagingLocation())
+        .rewriteLocationPrefix(tableWithPosDeletes.location(), 
targetTableLocation())
+        .execute();
+
+    RewriteTablePath.Result rerun =
+        actions()
+            .rewriteTablePath(tableWithPosDeletes)
+            .stagingLocation(stagingLocation())
+            .rewriteLocationPrefix(tableWithPosDeletes.location(), 
targetTableLocation())
+            .execute();
+    assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);
+  }
+
+  @TestTemplate
+  public void testRerunWithDVReusingStagingLocation() throws Exception {
+    assumeThat(formatVersion)
+        .as("Deletion vectors (Puffin files) are only used in format versions 
3+")
+        .isGreaterThanOrEqualTo(3);
+
+    Table tableWithDV =
+        createTableWithSnapshots(
+            tableDir.toFile().toURI().toString().concat("tableWithDVRerun"), 
2);
+
+    List<Pair<CharSequence, Long>> deletes =
+        Lists.newArrayList(
+            Pair.of(
+                SnapshotChanges.builderFor(tableWithDV)
+                    .build()
+                    .addedDataFiles()
+                    .iterator()
+                    .next()
+                    .location(),
+                0L));
+    File file =
+        new File(removePrefix(tableWithDV.location() + 
"/data/deeply/nested/deletes.puffin"));
+    DeleteFile dv =
+        FileHelpers.writeDeleteFile(
+                tableWithDV,
+                tableWithDV.io().newOutputFile(file.toURI().toString()),
+                deletes,
+                formatVersion)
+            .first();
+    tableWithDV.newRowDelta().addDeletes(dv).commit();
+
+    actions()
+        .rewriteTablePath(tableWithDV)
+        .stagingLocation(stagingLocation())
+        .rewriteLocationPrefix(tableWithDV.location(), targetTableLocation())
+        .execute();
+
+    // Rerunning to the same staging location must overwrite the previously 
written DV Puffin file
+    // instead of failing with AlreadyExistsException.
+    RewriteTablePath.Result rerun =
+        actions()
+            .rewriteTablePath(tableWithDV)
+            .stagingLocation(stagingLocation())
+            .rewriteLocationPrefix(tableWithDV.location(), 
targetTableLocation())
+            .execute();
+    assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);

Review Comment:
   nit: also verify if the final rewritten pats are correct 



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