2020 TYPE_CHECKING ,
2121 Any ,
2222 Dict ,
23- List ,
23+ Iterator ,
2424 Optional ,
2525 Set ,
2626 Tuple ,
@@ -385,7 +385,7 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
385385 database_name = self .identifier_to_database (namespace , NoSuchNamespaceError )
386386 table_identifiers = self .list_tables (namespace = database_name )
387387
388- if len (table_identifiers ) > 0 :
388+ if len (list ( table_identifiers ) ) > 0 :
389389 raise NamespaceNotEmptyError (f"Database { database_name } is not empty" )
390390
391391 try :
@@ -397,14 +397,14 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
397397 except ConditionalCheckFailedException as e :
398398 raise NoSuchNamespaceError (f"Database does not exist: { database_name } " ) from e
399399
400- def list_tables (self , namespace : Union [str , Identifier ]) -> List [Identifier ]:
400+ def list_tables (self , namespace : Union [str , Identifier ]) -> Iterator [Identifier ]:
401401 """List Iceberg tables under the given namespace in the catalog.
402402
403403 Args:
404404 namespace (str | Identifier): Namespace identifier to search.
405405
406406 Returns:
407- List [Identifier]: list of table identifiers.
407+ Iterator [Identifier]: iterator of table identifiers.
408408 """
409409 database_name = self .identifier_to_database (namespace , NoSuchNamespaceError )
410410
@@ -429,29 +429,26 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
429429 ) as e :
430430 raise GenericDynamoDbError (e .message ) from e
431431
432- table_identifiers = []
433432 for page in page_iterator :
434433 for item in page ["Items" ]:
435434 _dict = _convert_dynamo_item_to_regular_dict (item )
436435 identifier_col = _dict [DYNAMODB_COL_IDENTIFIER ]
437436 if identifier_col == DYNAMODB_NAMESPACE :
438437 continue
439438
440- table_identifiers . append ( self .identifier_to_tuple (identifier_col ) )
439+ yield self .identifier_to_tuple (identifier_col )
441440
442- return table_identifiers
443-
444- def list_namespaces (self , namespace : Union [str , Identifier ] = ()) -> List [Identifier ]:
441+ def list_namespaces (self , namespace : Union [str , Identifier ] = ()) -> Iterator [Identifier ]:
445442 """List top-level namespaces from the catalog.
446443
447444 We do not support hierarchical namespace.
448445
449446 Returns:
450- List [Identifier]: a List of namespace identifiers.
447+ Iterator [Identifier]: iterator of namespace identifiers.
451448 """
452449 # Hierarchical namespace is not supported. Return an empty list
453450 if namespace :
454- return []
451+ return
455452
456453 paginator = self .dynamodb .get_paginator ("query" )
457454
@@ -474,14 +471,11 @@ def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> List[Identi
474471 ) as e :
475472 raise GenericDynamoDbError (e .message ) from e
476473
477- database_identifiers = []
478474 for page in page_iterator :
479475 for item in page ["Items" ]:
480476 _dict = _convert_dynamo_item_to_regular_dict (item )
481477 namespace_col = _dict [DYNAMODB_COL_NAMESPACE ]
482- database_identifiers .append (self .identifier_to_tuple (namespace_col ))
483-
484- return database_identifiers
478+ yield self .identifier_to_tuple (namespace_col )
485479
486480 def load_namespace_properties (self , namespace : Union [str , Identifier ]) -> Properties :
487481 """
@@ -538,7 +532,7 @@ def update_namespace_properties(
538532
539533 return properties_update_summary
540534
541- def list_views (self , namespace : Union [str , Identifier ]) -> List [Identifier ]:
535+ def list_views (self , namespace : Union [str , Identifier ]) -> Iterator [Identifier ]:
542536 raise NotImplementedError
543537
544538 def drop_view (self , identifier : Union [str , Identifier ]) -> None :
0 commit comments