1818import logging
1919import socket
2020import time
21+ from collections .abc import Iterator
2122from types import TracebackType
2223from typing import (
2324 TYPE_CHECKING ,
@@ -479,7 +480,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str, o
479480 return self ._convert_hive_into_iceberg (hive_table )
480481
481482 @override
482- def list_views (self , namespace : str | Identifier ) -> list [Identifier ]:
483+ def list_views (self , namespace : str | Identifier ) -> Iterator [Identifier ]:
483484 raise NotImplementedError
484485
485486 @override
@@ -760,7 +761,7 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
760761 raise NoSuchNamespaceError (f"Database does not exists: { database_name } " ) from e
761762
762763 @override
763- def list_tables (self , namespace : str | Identifier ) -> list [Identifier ]:
764+ def list_tables (self , namespace : str | Identifier ) -> Iterator [Identifier ]:
764765 """List Iceberg tables under the given namespace in the catalog.
765766
766767 When the database doesn't exist, it will just return an empty list.
@@ -769,34 +770,36 @@ def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
769770 namespace: Database to list.
770771
771772 Returns:
772- List [Identifier]: list of table identifiers.
773+ Iterator [Identifier]: an iterator of table identifiers.
773774
774775 Raises:
775776 NoSuchNamespaceError: If a namespace with the given name does not exist, or the identifier is invalid.
776777 """
777778 database_name = self .identifier_to_database (namespace , NoSuchNamespaceError )
778779 with self ._client as open_client :
779- return [
780- (database_name , table .tableName )
781- for table in open_client .get_table_objects_by_name (
782- dbname = database_name , tbl_names = open_client .get_all_tables (db_name = database_name )
783- )
784- if table .parameters .get (TABLE_TYPE , "" ).lower () == ICEBERG
785- ]
780+ return iter (
781+ [
782+ (database_name , table .tableName )
783+ for table in open_client .get_table_objects_by_name (
784+ dbname = database_name , tbl_names = open_client .get_all_tables (db_name = database_name )
785+ )
786+ if table .parameters .get (TABLE_TYPE , "" ).lower () == ICEBERG
787+ ]
788+ )
786789
787790 @override
788- def list_namespaces (self , namespace : str | Identifier = ()) -> list [Identifier ]:
791+ def list_namespaces (self , namespace : str | Identifier = ()) -> Iterator [Identifier ]:
789792 """List namespaces from the given namespace. If not given, list top-level namespaces from the catalog.
790793
791794 Returns:
792- List [Identifier]: a List of namespace identifiers.
795+ Iterator [Identifier]: an iterator of namespace identifiers.
793796 """
794797 # Hierarchical namespace is not supported. Return an empty list
795798 if namespace :
796- return []
799+ return iter ([])
797800
798801 with self ._client as open_client :
799- return list (map (self .identifier_to_tuple , open_client .get_all_databases ()))
802+ return iter ( list (map (self .identifier_to_tuple , open_client .get_all_databases () )))
800803
801804 @override
802805 def load_namespace_properties (self , namespace : str | Identifier ) -> Properties :
0 commit comments