Skip to content

Commit 966d8b4

Browse files
committed
revert loop back, and address feedback
1 parent beaa930 commit 966d8b4

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.time.OffsetDateTime;
2727
import java.time.ZoneOffset;
2828
import java.util.Collections;
29-
import java.util.Iterator;
3029
import java.util.List;
3130
import java.util.Map;
3231
import java.util.Optional;
@@ -780,37 +779,31 @@ private static Pair<List<FileScanTask>, String> planFilesFor(
780779
TableScan tableScan, String planId, int tasksPerPlanTask) {
781780
Iterable<List<FileScanTask>> taskGroupings =
782781
Iterables.partition(tableScan.planFiles(), tasksPerPlanTask);
783-
Iterator<List<FileScanTask>> taskIterator = taskGroupings.iterator();
784-
String planTaskKeyPrefix = planId + "-" + tableScan.table().uuid() + "-";
785-
786-
if (!taskIterator.hasNext()) {
787-
// Handle empty table scans
788-
String emptyPlanTaskKey = planTaskKeyPrefix + 0;
789-
IN_MEMORY_PLANNING_STATE.addPlanTask(emptyPlanTaskKey, Collections.emptyList());
790-
return Pair.of(Collections.emptyList(), null);
791-
}
792-
793782
int planTaskSequence = 0;
794783
String previousPlanTask = null;
795784
String firstPlanTaskKey = null;
796785
List<FileScanTask> initialFileScanTasks = null;
786+
boolean hasPlanTasks = false;
797787

798-
do {
799-
List<FileScanTask> taskGrouping = taskIterator.next();
800-
String planTaskKey = planTaskKeyPrefix + planTaskSequence++;
788+
for (List<FileScanTask> taskGrouping : taskGroupings) {
789+
hasPlanTasks = true;
790+
String planTaskKey =
791+
String.format("%s-%s-%s", planId, tableScan.table().uuid(), planTaskSequence++);
801792
IN_MEMORY_PLANNING_STATE.addPlanTask(planTaskKey, taskGrouping);
802793

803-
if (firstPlanTaskKey == null) {
804-
firstPlanTaskKey = planTaskKey;
805-
initialFileScanTasks = taskGrouping;
806-
}
807-
808794
if (previousPlanTask != null) {
809795
IN_MEMORY_PLANNING_STATE.addNextPlanTask(previousPlanTask, planTaskKey);
796+
} else {
797+
firstPlanTaskKey = planTaskKey;
798+
initialFileScanTasks = taskGrouping;
810799
}
811800

812801
previousPlanTask = planTaskKey;
813-
} while (taskIterator.hasNext());
802+
}
803+
804+
if (!hasPlanTasks) {
805+
return Pair.of(Collections.emptyList(), null);
806+
}
814807

815808
return Pair.of(initialFileScanTasks, firstPlanTaskKey);
816809
}

0 commit comments

Comments
 (0)