@@ -150,6 +150,7 @@ class Endpoints:
150150 load_credentials : str = "namespaces/{namespace}/tables/{table}/credentials"
151151 update_table : str = "namespaces/{namespace}/tables/{table}"
152152 drop_table : str = "namespaces/{namespace}/tables/{table}"
153+ unregister_table : str = "namespaces/{namespace}/tables/{table}/unregister"
153154 table_exists : str = "namespaces/{namespace}/tables/{table}"
154155 get_token : str = "oauth/tokens"
155156 rename_table : str = "tables/rename"
@@ -182,6 +183,7 @@ class Capability:
182183 V1_DELETE_TABLE = Endpoint (http_method = HttpMethod .DELETE , path = f"{ API_PREFIX } /{ Endpoints .drop_table } " )
183184 V1_RENAME_TABLE = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .rename_table } " )
184185 V1_REGISTER_TABLE = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .register_table } " )
186+ V1_UNREGISTER_TABLE = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .unregister_table } " )
185187 V1_LOAD_CREDENTIALS = Endpoint (http_method = HttpMethod .GET , path = f"{ API_PREFIX } /{ Endpoints .load_credentials } " )
186188
187189 V1_LIST_VIEWS = Endpoint (http_method = HttpMethod .GET , path = f"{ API_PREFIX } /{ Endpoints .list_views } " )
@@ -338,6 +340,16 @@ class RegisterTableRequest(IcebergBaseModel):
338340 overwrite : bool
339341
340342
343+ class UnregisterTableResult (IcebergBaseModel ):
344+ """Result of unregistering a table.
345+
346+ Contains the last metadata location and table metadata at the time of unregistration.
347+ """
348+
349+ metadata_location : str = Field (..., alias = "metadata-location" )
350+ metadata : TableMetadata
351+
352+
341353class RegisterViewRequest (IcebergBaseModel ):
342354 name : str
343355 metadata_location : str = Field (..., alias = "metadata-location" )
@@ -1042,6 +1054,32 @@ def register_table(self, identifier: str | Identifier, metadata_location: str, o
10421054 table_response = TableResponse .model_validate_json (response .text )
10431055 return self ._response_to_table (self .identifier_to_tuple (identifier ), table_response )
10441056
1057+ @retry (** _RETRY_ARGS )
1058+ def unregister_table (self , identifier : str | Identifier ) -> tuple [str , TableMetadata ]:
1059+ """Unregister a table from the catalog without removing data or metadata files.
1060+
1061+ Args:
1062+ identifier (Union[str, Identifier]): Table identifier for the table
1063+
1064+ Returns:
1065+ tuple[str, TableMetadata]: The last metadata location and corresponding table metadata
1066+
1067+ Raises:
1068+ NoSuchTableError: If the table does not exist
1069+ """
1070+ self ._check_endpoint (Capability .V1_UNREGISTER_TABLE )
1071+ namespace_and_table = self ._split_identifier_for_path (identifier )
1072+ response = self ._session .post (
1073+ self .url (Endpoints .unregister_table , prefixed = True , ** namespace_and_table ),
1074+ )
1075+ try :
1076+ response .raise_for_status ()
1077+ except HTTPError as exc :
1078+ _handle_non_200_response (exc , {404 : NoSuchTableError })
1079+
1080+ result = UnregisterTableResult .model_validate_json (response .content )
1081+ return (result .metadata_location , result .metadata )
1082+
10451083 @retry (** _RETRY_ARGS )
10461084 @override
10471085 def list_tables (self , namespace : str | Identifier ) -> list [Identifier ]:
0 commit comments