2020 Any ,
2121 Dict ,
2222 List ,
23+ Optional ,
2324 Set ,
2425 Tuple ,
2526 Union ,
@@ -152,18 +153,18 @@ def _retry_hook(retry_state: RetryCallState) -> None:
152153
153154
154155class TableResponse (IcebergBaseModel ):
155- metadata_location : str | None = Field (alias = "metadata-location" , default = None )
156+ metadata_location : Optional [ str ] = Field (alias = "metadata-location" , default = None )
156157 metadata : TableMetadata
157158 config : Properties = Field (default_factory = dict )
158- storage_credentials : Properties | None = Field (alias = "storage-credentials" , default = None )
159+ storage_credentials : Optional [ Properties ] = Field (alias = "storage-credentials" , default = None )
159160
160161
161162class CreateTableRequest (IcebergBaseModel ):
162163 name : str = Field ()
163- location : str | None = Field ()
164+ location : Optional [ str ] = Field ()
164165 table_schema : Schema = Field (alias = "schema" )
165- partition_spec : PartitionSpec | None = Field (alias = "partition-spec" )
166- write_order : SortOrder | None = Field (alias = "write-order" )
166+ partition_spec : Optional [ PartitionSpec ] = Field (alias = "partition-spec" )
167+ write_order : Optional [ SortOrder ] = Field (alias = "write-order" )
167168 stage_create : bool = Field (alias = "stage-create" , default = False )
168169 properties : Dict [str , str ] = Field (default_factory = dict )
169170
@@ -179,8 +180,8 @@ class RegisterTableRequest(IcebergBaseModel):
179180
180181
181182class ConfigResponse (IcebergBaseModel ):
182- defaults : Properties | None = Field (default_factory = dict )
183- overrides : Properties | None = Field (default_factory = dict )
183+ defaults : Optional [ Properties ] = Field (default_factory = dict )
184+ overrides : Optional [ Properties ] = Field (default_factory = dict )
184185
185186
186187class ListNamespaceResponse (IcebergBaseModel ):
@@ -294,7 +295,7 @@ def _create_legacy_oauth2_auth_manager(self, session: Session) -> AuthManager:
294295
295296 return AuthManagerFactory .create ("legacyoauth2" , auth_config )
296297
297- def _check_valid_namespace_identifier (self , identifier : str | Identifier ) -> Identifier :
298+ def _check_valid_namespace_identifier (self , identifier : Union [ str , Identifier ] ) -> Identifier :
298299 """Check if the identifier has at least one element."""
299300 identifier_tuple = Catalog .identifier_to_tuple (identifier )
300301 if len (identifier_tuple ) < 1 :
@@ -377,22 +378,22 @@ def _fetch_config(self) -> None:
377378 # Update URI based on overrides
378379 self .uri = config [URI ]
379380
380- def _identifier_to_validated_tuple (self , identifier : str | Identifier ) -> Identifier :
381+ def _identifier_to_validated_tuple (self , identifier : Union [ str , Identifier ] ) -> Identifier :
381382 identifier_tuple = self .identifier_to_tuple (identifier )
382383 if len (identifier_tuple ) <= 1 :
383384 raise NoSuchIdentifierError (f"Missing namespace or invalid identifier: { '.' .join (identifier_tuple )} " )
384385 return identifier_tuple
385386
386387 def _split_identifier_for_path (
387- self , identifier : str | Identifier | TableIdentifier , kind : IdentifierKind = IdentifierKind .TABLE
388+ self , identifier : Union [ str , Identifier , TableIdentifier ] , kind : IdentifierKind = IdentifierKind .TABLE
388389 ) -> Properties :
389390 if isinstance (identifier , TableIdentifier ):
390391 return {"namespace" : NAMESPACE_SEPARATOR .join (identifier .namespace .root ), kind .value : identifier .name }
391392 identifier_tuple = self ._identifier_to_validated_tuple (identifier )
392393
393394 return {"namespace" : NAMESPACE_SEPARATOR .join (identifier_tuple [:- 1 ]), kind .value : identifier_tuple [- 1 ]}
394395
395- def _split_identifier_for_json (self , identifier : str | Identifier ) -> Dict [str , Identifier | str ]:
396+ def _split_identifier_for_json (self , identifier : Union [ str , Identifier ] ) -> Dict [str , Union [ Identifier , str ] ]:
396397 identifier_tuple = self ._identifier_to_validated_tuple (identifier )
397398 return {"namespace" : identifier_tuple [:- 1 ], "name" : identifier_tuple [- 1 ]}
398399
@@ -496,9 +497,9 @@ def _config_headers(self, session: Session) -> None:
496497
497498 def _create_table (
498499 self ,
499- identifier : str | Identifier ,
500+ identifier : Union [ str , Identifier ] ,
500501 schema : Union [Schema , "pa.Schema" ],
501- location : str | None = None ,
502+ location : Optional [ str ] = None ,
502503 partition_spec : PartitionSpec = UNPARTITIONED_PARTITION_SPEC ,
503504 sort_order : SortOrder = UNSORTED_SORT_ORDER ,
504505 properties : Properties = EMPTY_DICT ,
@@ -538,9 +539,9 @@ def _create_table(
538539 @retry (** _RETRY_ARGS )
539540 def create_table (
540541 self ,
541- identifier : str | Identifier ,
542+ identifier : Union [ str , Identifier ] ,
542543 schema : Union [Schema , "pa.Schema" ],
543- location : str | None = None ,
544+ location : Optional [ str ] = None ,
544545 partition_spec : PartitionSpec = UNPARTITIONED_PARTITION_SPEC ,
545546 sort_order : SortOrder = UNSORTED_SORT_ORDER ,
546547 properties : Properties = EMPTY_DICT ,
@@ -559,9 +560,9 @@ def create_table(
559560 @retry (** _RETRY_ARGS )
560561 def create_table_transaction (
561562 self ,
562- identifier : str | Identifier ,
563+ identifier : Union [ str , Identifier ] ,
563564 schema : Union [Schema , "pa.Schema" ],
564- location : str | None = None ,
565+ location : Optional [ str ] = None ,
565566 partition_spec : PartitionSpec = UNPARTITIONED_PARTITION_SPEC ,
566567 sort_order : SortOrder = UNSORTED_SORT_ORDER ,
567568 properties : Properties = EMPTY_DICT ,
@@ -579,7 +580,7 @@ def create_table_transaction(
579580 return CreateTableTransaction (staged_table )
580581
581582 @retry (** _RETRY_ARGS )
582- def register_table (self , identifier : str | Identifier , metadata_location : str ) -> Table :
583+ def register_table (self , identifier : Union [ str , Identifier ] , metadata_location : str ) -> Table :
583584 """Register a new table using existing metadata.
584585
585586 Args:
@@ -611,7 +612,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str) -
611612 return self ._response_to_table (self .identifier_to_tuple (identifier ), table_response )
612613
613614 @retry (** _RETRY_ARGS )
614- def list_tables (self , namespace : str | Identifier ) -> List [Identifier ]:
615+ def list_tables (self , namespace : Union [ str , Identifier ] ) -> List [Identifier ]:
615616 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
616617 namespace_concat = NAMESPACE_SEPARATOR .join (namespace_tuple )
617618 response = self ._session .get (self .url (Endpoints .list_tables , namespace = namespace_concat ))
@@ -622,7 +623,7 @@ def list_tables(self, namespace: str | Identifier) -> List[Identifier]:
622623 return [(* table .namespace , table .name ) for table in ListTablesResponse .model_validate_json (response .text ).identifiers ]
623624
624625 @retry (** _RETRY_ARGS )
625- def load_table (self , identifier : str | Identifier ) -> Table :
626+ def load_table (self , identifier : Union [ str , Identifier ] ) -> Table :
626627 params = {}
627628 if mode := self .properties .get (SNAPSHOT_LOADING_MODE ):
628629 if mode in {"all" , "refs" }:
@@ -642,7 +643,7 @@ def load_table(self, identifier: str | Identifier) -> Table:
642643 return self ._response_to_table (self .identifier_to_tuple (identifier ), table_response )
643644
644645 @retry (** _RETRY_ARGS )
645- def drop_table (self , identifier : str | Identifier , purge_requested : bool = False ) -> None :
646+ def drop_table (self , identifier : Union [ str , Identifier ] , purge_requested : bool = False ) -> None :
646647 response = self ._session .delete (
647648 self .url (Endpoints .drop_table , prefixed = True , ** self ._split_identifier_for_path (identifier )),
648649 params = {"purgeRequested" : purge_requested },
@@ -653,11 +654,11 @@ def drop_table(self, identifier: str | Identifier, purge_requested: bool = False
653654 _handle_non_200_response (exc , {404 : NoSuchTableError })
654655
655656 @retry (** _RETRY_ARGS )
656- def purge_table (self , identifier : str | Identifier ) -> None :
657+ def purge_table (self , identifier : Union [ str , Identifier ] ) -> None :
657658 self .drop_table (identifier = identifier , purge_requested = True )
658659
659660 @retry (** _RETRY_ARGS )
660- def rename_table (self , from_identifier : str | Identifier , to_identifier : str | Identifier ) -> Table :
661+ def rename_table (self , from_identifier : Union [ str , Identifier ] , to_identifier : Union [ str , Identifier ] ) -> Table :
661662 payload = {
662663 "source" : self ._split_identifier_for_json (from_identifier ),
663664 "destination" : self ._split_identifier_for_json (to_identifier ),
@@ -682,7 +683,7 @@ def _remove_catalog_name_from_table_request_identifier(self, table_request: Comm
682683 return table_request
683684
684685 @retry (** _RETRY_ARGS )
685- def list_views (self , namespace : str | Identifier ) -> List [Identifier ]:
686+ def list_views (self , namespace : Union [ str , Identifier ] ) -> List [Identifier ]:
686687 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
687688 namespace_concat = NAMESPACE_SEPARATOR .join (namespace_tuple )
688689 response = self ._session .get (self .url (Endpoints .list_views , namespace = namespace_concat ))
@@ -739,7 +740,7 @@ def commit_table(
739740 return CommitTableResponse .model_validate_json (response .text )
740741
741742 @retry (** _RETRY_ARGS )
742- def create_namespace (self , namespace : str | Identifier , properties : Properties = EMPTY_DICT ) -> None :
743+ def create_namespace (self , namespace : Union [ str , Identifier ] , properties : Properties = EMPTY_DICT ) -> None :
743744 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
744745 payload = {"namespace" : namespace_tuple , "properties" : properties }
745746 response = self ._session .post (self .url (Endpoints .create_namespace ), json = payload )
@@ -749,7 +750,7 @@ def create_namespace(self, namespace: str | Identifier, properties: Properties =
749750 _handle_non_200_response (exc , {409 : NamespaceAlreadyExistsError })
750751
751752 @retry (** _RETRY_ARGS )
752- def drop_namespace (self , namespace : str | Identifier ) -> None :
753+ def drop_namespace (self , namespace : Union [ str , Identifier ] ) -> None :
753754 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
754755 namespace = NAMESPACE_SEPARATOR .join (namespace_tuple )
755756 response = self ._session .delete (self .url (Endpoints .drop_namespace , namespace = namespace ))
@@ -759,7 +760,7 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
759760 _handle_non_200_response (exc , {404 : NoSuchNamespaceError , 409 : NamespaceNotEmptyError })
760761
761762 @retry (** _RETRY_ARGS )
762- def list_namespaces (self , namespace : str | Identifier = ()) -> List [Identifier ]:
763+ def list_namespaces (self , namespace : Union [ str , Identifier ] = ()) -> List [Identifier ]:
763764 namespace_tuple = self .identifier_to_tuple (namespace )
764765 response = self ._session .get (
765766 self .url (
@@ -776,7 +777,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> List[Identifier]:
776777 return ListNamespaceResponse .model_validate_json (response .text ).namespaces
777778
778779 @retry (** _RETRY_ARGS )
779- def load_namespace_properties (self , namespace : str | Identifier ) -> Properties :
780+ def load_namespace_properties (self , namespace : Union [ str , Identifier ] ) -> Properties :
780781 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
781782 namespace = NAMESPACE_SEPARATOR .join (namespace_tuple )
782783 response = self ._session .get (self .url (Endpoints .load_namespace_metadata , namespace = namespace ))
@@ -789,7 +790,7 @@ def load_namespace_properties(self, namespace: str | Identifier) -> Properties:
789790
790791 @retry (** _RETRY_ARGS )
791792 def update_namespace_properties (
792- self , namespace : str | Identifier , removals : Set [str ] | None = None , updates : Properties = EMPTY_DICT
793+ self , namespace : Union [ str , Identifier ] , removals : Optional [ Set [str ]] = None , updates : Properties = EMPTY_DICT
793794 ) -> PropertiesUpdateSummary :
794795 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
795796 namespace = NAMESPACE_SEPARATOR .join (namespace_tuple )
@@ -807,7 +808,7 @@ def update_namespace_properties(
807808 )
808809
809810 @retry (** _RETRY_ARGS )
810- def namespace_exists (self , namespace : str | Identifier ) -> bool :
811+ def namespace_exists (self , namespace : Union [ str , Identifier ] ) -> bool :
811812 namespace_tuple = self ._check_valid_namespace_identifier (namespace )
812813 namespace = NAMESPACE_SEPARATOR .join (namespace_tuple )
813814 response = self ._session .head (self .url (Endpoints .namespace_exists , namespace = namespace ))
@@ -825,7 +826,7 @@ def namespace_exists(self, namespace: str | Identifier) -> bool:
825826 return False
826827
827828 @retry (** _RETRY_ARGS )
828- def table_exists (self , identifier : str | Identifier ) -> bool :
829+ def table_exists (self , identifier : Union [ str , Identifier ] ) -> bool :
829830 """Check if a table exists.
830831
831832 Args:
@@ -851,7 +852,7 @@ def table_exists(self, identifier: str | Identifier) -> bool:
851852 return False
852853
853854 @retry (** _RETRY_ARGS )
854- def view_exists (self , identifier : str | Identifier ) -> bool :
855+ def view_exists (self , identifier : Union [ str , Identifier ] ) -> bool :
855856 """Check if a view exists.
856857
857858 Args:
@@ -876,7 +877,7 @@ def view_exists(self, identifier: str | Identifier) -> bool:
876877 return False
877878
878879 @retry (** _RETRY_ARGS )
879- def drop_view (self , identifier : str ) -> None :
880+ def drop_view (self , identifier : Union [ str ] ) -> None :
880881 response = self ._session .delete (
881882 self .url (Endpoints .drop_view , prefixed = True , ** self ._split_identifier_for_path (identifier , IdentifierKind .VIEW )),
882883 )
@@ -890,4 +891,4 @@ def close(self) -> None:
890891
891892 This method closes mounted HttpAdapters' pooled connections and any active Proxy pooled connections.
892893 """
893- self ._session .close ()
894+ self ._session .close ()
0 commit comments