zhoujinsong commented on code in PR #3546:
URL: https://github.com/apache/amoro/pull/3546#discussion_r2131839667


##########
amoro-format-iceberg/src/main/java/org/apache/amoro/optimizing/plan/AbstractOptimizingPlanner.java:
##########
@@ -151,27 +151,33 @@ public List<RewriteStageTask> planTasks() {
       return cacheAndReturnTasks(Collections.emptyList());
     }
 
-    List<PartitionEvaluator> evaluators = new 
ArrayList<>(needOptimizingPlanMap.values());
+    LinkedList<PartitionEvaluator> evaluators = new 
LinkedList<>(needOptimizingPlanMap.values());
     // prioritize partitions with high cost to avoid starvation
     evaluators.sort(Comparator.comparing(PartitionEvaluator::getWeight, 
Comparator.reverseOrder()));
 
     double maxInputSize = maxInputSizePerThread * availableCore;
     actualPartitionPlans = Lists.newArrayList();
     long actualInputSize = 0;
-    for (PartitionEvaluator evaluator : evaluators) {
-      actualPartitionPlans.add((AbstractPartitionPlan) evaluator);
-      actualInputSize += evaluator.getCost();
-      if (actualInputSize > maxInputSize) {
-        break;
+    List<RewriteStageTask> plannedTasks = Lists.newArrayList();
+
+    while (plannedTasks.isEmpty() && !evaluators.isEmpty()) {
+      for (PartitionEvaluator evaluator = evaluators.poll();
+          evaluator != null;
+          evaluator = evaluators.poll()) {
+        actualPartitionPlans.add((AbstractPartitionPlan) evaluator);
+        actualInputSize += evaluator.getCost();

Review Comment:
   Nice catch!
   
   But I am wondering if we should calculate the input size depending on the 
real tasks from plannedTasks rather than `evaluator#cost` if the cost is not 
true.



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

Reply via email to