RussellSpitzer commented on a change in pull request #1313:
URL: https://github.com/apache/iceberg/pull/1313#discussion_r467932715



##########
File path: 
spark/src/main/java/org/apache/iceberg/actions/RemoveOrphanFilesAction.java
##########
@@ -161,15 +172,44 @@ public RemoveOrphanFilesAction 
deleteWith(Consumer<String> newDeleteFunc) {
         .as(Encoders.STRING())
         .collectAsList();
 
-    Tasks.foreach(orphanFiles)
-        .noRetry()
-        .suppressFailureWhenFinished()
-        .onFailure((file, exc) -> LOG.warn("Failed to delete file: {}", file, 
exc))
-        .run(deleteFunc::accept);
+    paralleExecutor(sparkContext, orphanFiles, excutorTaskNum, deleteFunc);
 
     return orphanFiles;
   }
 
+  private void paralleExecutor(JavaSparkContext javaSc, List<String> 
orphanFiles,
+                              int numSlices, Consumer deleteConsumer) {
+    if (numSlices == 0) {
+      Tasks.foreach(orphanFiles)
+          .noRetry()
+          .suppressFailureWhenFinished()
+          .onFailure((file, exc) -> LOG.warn("Failed to delete file: {}", 
file, exc))
+          .run(deleteConsumer::accept);
+    } else {
+      javaSc.parallelize(orphanFiles, numSlices).foreachPartition(row -> {
+        List<String> orphanFileList = IteratorUtils.toList(row);
+        Tasks.foreach(orphanFileList)
+            .noRetry()
+            .suppressFailureWhenFinished()
+            .onFailure((file, exc) -> LOG.warn("Failed to delete file: {}", 
file, exc))
+            .run(deleteConsumer::accept);
+      });
+    }
+  }
+
+  public static class DeleteConsumer implements Consumer<String>, Serializable 
{

Review comment:
       I wonder if it makes sense to add a Serializable Consumer class as a 
utility. Then have this DeleteConsumer extend that.




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

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