rdblue commented on code in PR #5077:
URL: https://github.com/apache/iceberg/pull/5077#discussion_r906274588


##########
core/src/main/java/org/apache/iceberg/util/TableScanUtil.java:
##########
@@ -78,4 +86,71 @@ public static CloseableIterable<CombinedScanTask> 
planTasks(CloseableIterable<Fi
             splitFiles),
         BaseCombinedScanTask::new);
   }
+
+  @SuppressWarnings("unchecked")
+  public static <T extends ScanTask> CloseableIterable<ScanTaskGroup<T>> 
planTaskGroups(CloseableIterable<T> tasks,
+                                                                               
         long splitSize, int lookback,
+                                                                               
         long openFileCost) {
+
+    Preconditions.checkArgument(splitSize > 0, "Invalid split size (negative 
or 0): %s", splitSize);
+    Preconditions.checkArgument(lookback > 0, "Invalid split planning lookback 
(negative or 0): %s", lookback);
+    Preconditions.checkArgument(openFileCost >= 0, "Invalid file open cost 
(negative): %s", openFileCost);
+
+    // capture manifests which can be closed after scan planning
+    CloseableIterable<T> splitTasks = CloseableIterable.combine(
+        FluentIterable.from(tasks).transformAndConcat(task -> {
+          if (task instanceof SplittableScanTask<?>) {
+            return ((SplittableScanTask<? extends T>) task).split(splitSize);
+          } else {
+            return ImmutableList.of(task);
+          }
+        }),
+        tasks);
+
+    Function<T, Long> weightFunc = task -> Math.max(task.sizeBytes(), 
task.filesCount() * openFileCost);
+
+    return CloseableIterable.transform(
+        CloseableIterable.combine(
+            new BinPacking.PackingIterable<>(splitTasks, splitSize, lookback, 
weightFunc, true),
+            splitTasks),
+        combinedTasks -> new BaseScanTaskGroup<>(combineTasks(combinedTasks)));
+  }
+
+  @SuppressWarnings("unchecked")
+  public static <T extends ScanTask> List<T> combineTasks(List<T> tasks) {
+    if (tasks.isEmpty()) {
+      return tasks;
+    }
+
+    List<T> combinedTasks = Lists.newArrayList();
+    CombinableScanTask<? extends T> lastCombinableTask = null;
+
+    for (T task : tasks) {
+      if (task instanceof CombinableScanTask<?>) {

Review Comment:
   I don't think this is correct. It doesn't matter if the next task is 
combineable. It only matters if the last task was. And we can't keep around the 
last _combineable_ task because then we would possibly combine tasks out of 
order.
   
   I think `lastCombineableTask` should be `lastTask` and this should check 
whether `lastTask` is a combineable in order to try combining with the current 
task. The new task, if not combined, should always be set as the new `lastTask`.



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