1515# specific language governing permissions and limitations
1616# under the License.
1717from collections import deque
18- from collections .abc import Iterator
1918from enum import Enum
2019from typing import (
2120 TYPE_CHECKING ,
@@ -460,18 +459,17 @@ def _fetch_scan_tasks(self, identifier: str | Identifier, plan_task: str) -> Sca
460459
461460 return ScanTasks .model_validate_json (response .text )
462461
463- def plan_scan (self , identifier : str | Identifier , request : PlanTableScanRequest ) -> Iterator ["FileScanTask" ]:
464- """Plan a table scan and yield FileScanTasks.
462+ def plan_scan (self , identifier : str | Identifier , request : PlanTableScanRequest ) -> list ["FileScanTask" ]:
463+ """Plan a table scan and return FileScanTasks.
465464
466465 Handles the full scan planning lifecycle including pagination.
467- Each response batch is self-contained, so tasks are yielded as received.
468466
469467 Args:
470468 identifier: Table identifier.
471469 request: The scan plan request parameters.
472470
473- Yields :
474- FileScanTask objects ready for execution.
471+ Returns :
472+ List of FileScanTask objects ready for execution.
475473
476474 Raises:
477475 RuntimeError: If planning fails, is cancelled, or returns unexpected response.
@@ -492,19 +490,23 @@ def plan_scan(self, identifier: str | Identifier, request: PlanTableScanRequest)
492490 if not isinstance (response , PlanCompleted ):
493491 raise RuntimeError (f"Invalid planStatus for response: { type (response ).__name__ } " )
494492
495- # Yield tasks from initial response
493+ tasks : list [FileScanTask ] = []
494+
495+ # Collect tasks from initial response
496496 for task in response .file_scan_tasks :
497- yield FileScanTask .from_rest_response (task , response .delete_files )
497+ tasks . append ( FileScanTask .from_rest_response (task , response .delete_files ) )
498498
499- # Fetch and yield from additional batches
499+ # Fetch and collect from additional batches
500500 pending_tasks = deque (response .plan_tasks )
501501 while pending_tasks :
502502 plan_task = pending_tasks .popleft ()
503503 batch = self ._fetch_scan_tasks (identifier , plan_task )
504504 for task in batch .file_scan_tasks :
505- yield FileScanTask .from_rest_response (task , batch .delete_files )
505+ tasks . append ( FileScanTask .from_rest_response (task , batch .delete_files ) )
506506 pending_tasks .extend (batch .plan_tasks )
507507
508+ return tasks
509+
508510 def _create_legacy_oauth2_auth_manager (self , session : Session ) -> AuthManager :
509511 """Create the LegacyOAuth2AuthManager by fetching required properties.
510512
0 commit comments