@@ -302,19 +302,20 @@ def _fetch_config(self) -> None:
302
302
# Update URI based on overrides
303
303
self .uri = config [URI ]
304
304
305
- def _split_identifier_for_path (self , identifier : Union [str , Identifier , TableIdentifier ]) -> Properties :
306
- if isinstance (identifier , TableIdentifier ):
307
- return {"namespace" : NAMESPACE_SEPARATOR .join (identifier .namespace .root [1 :]), "table" : identifier .name }
308
-
305
+ def _identifier_to_validated_tuple (self , identifier : Union [str , Identifier ]) -> Identifier :
309
306
identifier_tuple = self .identifier_to_tuple (identifier )
310
307
if len (identifier_tuple ) <= 1 :
311
308
raise NoSuchTableError (f"Missing namespace or invalid identifier: { '.' .join (identifier_tuple )} " )
309
+ return identifier_tuple
310
+
311
+ def _split_identifier_for_path (self , identifier : Union [str , Identifier , TableIdentifier ]) -> Properties :
312
+ if isinstance (identifier , TableIdentifier ):
313
+ return {"namespace" : NAMESPACE_SEPARATOR .join (identifier .namespace .root [1 :]), "table" : identifier .name }
314
+ identifier_tuple = self ._identifier_to_validated_tuple (identifier )
312
315
return {"namespace" : NAMESPACE_SEPARATOR .join (identifier_tuple [:- 1 ]), "table" : identifier_tuple [- 1 ]}
313
316
314
317
def _split_identifier_for_json (self , identifier : Union [str , Identifier ]) -> Dict [str , Union [Identifier , str ]]:
315
- identifier_tuple = self .identifier_to_tuple (identifier )
316
- if len (identifier_tuple ) <= 1 :
317
- raise NoSuchTableError (f"Missing namespace or invalid identifier: { identifier_tuple } " )
318
+ identifier_tuple = self ._identifier_to_validated_tuple (identifier )
318
319
return {"namespace" : identifier_tuple [:- 1 ], "name" : identifier_tuple [- 1 ]}
319
320
320
321
def _handle_non_200_response (self , exc : HTTPError , error_handler : Dict [int , Type [Exception ]]) -> None :
@@ -499,12 +500,10 @@ def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
499
500
return [(* table .namespace , table .name ) for table in ListTablesResponse (** response .json ()).identifiers ]
500
501
501
502
def load_table (self , identifier : Union [str , Identifier ]) -> Table :
502
- identifier_tuple = self .identifier_to_tuple (identifier )
503
-
504
- if len (identifier_tuple ) <= 1 :
505
- raise NoSuchTableError (f"Missing namespace or invalid identifier: { identifier } " )
506
-
507
- response = self ._session .get (self .url (Endpoints .load_table , prefixed = True , ** self ._split_identifier_for_path (identifier )))
503
+ identifier_tuple = self .identifier_to_tuple_without_catalog (identifier )
504
+ response = self ._session .get (
505
+ self .url (Endpoints .load_table , prefixed = True , ** self ._split_identifier_for_path (identifier_tuple ))
506
+ )
508
507
try :
509
508
response .raise_for_status ()
510
509
except HTTPError as exc :
@@ -514,8 +513,11 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
514
513
return self ._response_to_table (identifier_tuple , table_response )
515
514
516
515
def drop_table (self , identifier : Union [str , Identifier ], purge_requested : bool = False ) -> None :
516
+ identifier_tuple = self .identifier_to_tuple_without_catalog (identifier )
517
517
response = self ._session .delete (
518
- self .url (Endpoints .drop_table , prefixed = True , purge = purge_requested , ** self ._split_identifier_for_path (identifier )),
518
+ self .url (
519
+ Endpoints .drop_table , prefixed = True , purge = purge_requested , ** self ._split_identifier_for_path (identifier_tuple )
520
+ ),
519
521
)
520
522
try :
521
523
response .raise_for_status ()
@@ -526,8 +528,9 @@ def purge_table(self, identifier: Union[str, Identifier]) -> None:
526
528
self .drop_table (identifier = identifier , purge_requested = True )
527
529
528
530
def rename_table (self , from_identifier : Union [str , Identifier ], to_identifier : Union [str , Identifier ]) -> Table :
531
+ from_identifier_tuple = self .identifier_to_tuple_without_catalog (from_identifier )
529
532
payload = {
530
- "source" : self ._split_identifier_for_json (from_identifier ),
533
+ "source" : self ._split_identifier_for_json (from_identifier_tuple ),
531
534
"destination" : self ._split_identifier_for_json (to_identifier ),
532
535
}
533
536
response = self ._session .post (self .url (Endpoints .rename_table ), json = payload )
0 commit comments