@@ -678,7 +678,6 @@ public static PlanTableScanResponse planTableScan(
678678 initial .second () == null
679679 ? Collections .emptyList ()
680680 : IN_MEMORY_PLANNING_STATE .nextPlanTask (initial .second ());
681-
682681 PlanTableScanResponse .Builder builder =
683682 PlanTableScanResponse .builder ()
684683 .withPlanStatus (PlanStatus .COMPLETED )
@@ -777,20 +776,25 @@ static void clearPlanningState() {
777776 */
778777 private static Pair <List <FileScanTask >, String > planFilesFor (
779778 TableScan tableScan , String planId , int tasksPerPlanTask ) {
780- Iterable <List <FileScanTask >> taskGroupings =
781- Iterables .partition (tableScan .planFiles (), tasksPerPlanTask );
779+ Iterable <FileScanTask > planTasks = tableScan .planFiles ();
780+ String planTaskPrefix = planId + "-" + tableScan .table ().uuid () + "-" ;
781+
782+ // Handle empty table scans
783+ if (!planTasks .iterator ().hasNext ()) {
784+ String planTaskKey = planTaskPrefix + "0" ;
785+ // Add empty scan to planning state so async calls know the scan completed
786+ IN_MEMORY_PLANNING_STATE .addPlanTask (planTaskKey , Collections .emptyList ());
787+ return Pair .of (Collections .emptyList (), planTaskKey );
788+ }
789+
790+ Iterable <List <FileScanTask >> taskGroupings = Iterables .partition (planTasks , tasksPerPlanTask );
782791 int planTaskSequence = 0 ;
783792 String previousPlanTask = null ;
784793 String firstPlanTaskKey = null ;
785794 List <FileScanTask > initialFileScanTasks = null ;
786- boolean hasPlanTasks = false ;
787-
788795 for (List <FileScanTask > taskGrouping : taskGroupings ) {
789- hasPlanTasks = true ;
790- String planTaskKey =
791- String .format ("%s-%s-%s" , planId , tableScan .table ().uuid (), planTaskSequence ++);
796+ String planTaskKey = planTaskPrefix + planTaskSequence ++;
792797 IN_MEMORY_PLANNING_STATE .addPlanTask (planTaskKey , taskGrouping );
793-
794798 if (previousPlanTask != null ) {
795799 IN_MEMORY_PLANNING_STATE .addNextPlanTask (previousPlanTask , planTaskKey );
796800 } else {
@@ -800,11 +804,6 @@ private static Pair<List<FileScanTask>, String> planFilesFor(
800804
801805 previousPlanTask = planTaskKey ;
802806 }
803-
804- if (!hasPlanTasks ) {
805- return Pair .of (Collections .emptyList (), null );
806- }
807-
808807 return Pair .of (initialFileScanTasks , firstPlanTaskKey );
809808 }
810809
0 commit comments