microbearz commented on a change in pull request #4451:
URL: https://github.com/apache/iceberg/pull/4451#discussion_r841058866



##########
File path: 
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/actions/BaseDeleteOrphanFilesSparkAction.java
##########
@@ -172,17 +174,29 @@ private String jobDesc() {
     Column nameEqual = actualFileName.equalTo(validFileName);
     Column actualContains = 
actualFileDF.col("file_path").contains(validFileDF.col("file_path"));
     Column joinCond = nameEqual.and(actualContains);
-    List<String> orphanFiles = actualFileDF.join(validFileDF, joinCond, 
"leftanti")
-        .as(Encoders.STRING())
-        .collectAsList();
-
-    Tasks.foreach(orphanFiles)
-        .noRetry()
-        .executeWith(deleteExecutorService)
-        .suppressFailureWhenFinished()
-        .onFailure((file, exc) -> LOG.warn("Failed to delete file: {}", file, 
exc))
-        .run(deleteFunc::accept);
+    Dataset<String> orphanDF = actualFileDF.join(validFileDF, joinCond, 
"leftanti")
+            .as(Encoders.STRING());
+    return deleteFiles(orphanDF);
+  }
 
+  private BaseDeleteOrphanFilesActionResult deleteFiles(Dataset<String> 
orphanDF) {
+    boolean streamResults = PropertyUtil.propertyAsBoolean(options(), 
STREAM_RESULTS, false);
+    Iterator<String> itr;
+    if (streamResults) {
+      itr = orphanDF.toLocalIterator();
+    } else {
+      itr = orphanDF.collectAsList().iterator();
+    }
+    List<String> orphanFiles = 
Collections.synchronizedList(Lists.newArrayList());

Review comment:
       @RussellSpitzer thanks for your reminder. To avoid materializing job in 
memory, when `stream-results` enabled, we can streaming the results like:
   ```
   if (streamResults) {
         return new BaseDeleteOrphanFilesActionResult(() -> 
orphanDF.toLocalIterator());
       } else {
         return new BaseDeleteOrphanFilesActionResult(orphanDF.collectAsList());
       }
   ```
   




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