Baunsgaard commented on code in PR #18551:
URL: https://github.com/apache/iceberg/pull/18551#discussion_r4395033658


##########
spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/actions/DeleteOrphanFilesSparkAction.java:
##########
@@ -466,6 +467,15 @@ private Dataset<String> listedFileDS() {
     }
   }
 
+  private JavaRDD<String> matchingFilesRDD(List<String> matchingFiles) {
+    int numPartitions =
+        Math.max(
+            1,
+            (matchingFiles.size() + MAX_LISTED_FILES_PER_PARTITION - 1)
+                / MAX_LISTED_FILES_PER_PARTITION);

Review Comment:
   The calculation is correct but the add can overflow. Since the sum wraps to 
`Integer.MIN_VALUE` and `Math.max(1, …)` returns 1 it would default back to the 
 original single-partition and OOM.
   
   Not really a practical case since the driver probably already OOMed from the 
List<String> , but other methods calculate like this: 
   
   ```java
   int numPartitions = IntMath.divide(matchingFiles.size(), 
      MAX_LISTED_FILES_PER_PARTITION, RoundingMode.CEILING);
   numPartitions = Math.max(1, numPartitions);
   ```



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