@@ -153,6 +153,7 @@ class Endpoints:
153153 rename_table : str = "tables/rename"
154154 list_views : str = "namespaces/{namespace}/views"
155155 create_view : str = "namespaces/{namespace}/views"
156+ register_view : str = "namespaces/{namespace}/register-view"
156157 drop_view : str = "namespaces/{namespace}/views/{view}"
157158 view_exists : str = "namespaces/{namespace}/views/{view}"
158159 plan_table_scan : str = "namespaces/{namespace}/tables/{table}/plan"
@@ -181,6 +182,7 @@ class Capability:
181182
182183 V1_LIST_VIEWS = Endpoint (http_method = HttpMethod .GET , path = f"{ API_PREFIX } /{ Endpoints .list_views } " )
183184 V1_VIEW_EXISTS = Endpoint (http_method = HttpMethod .HEAD , path = f"{ API_PREFIX } /{ Endpoints .view_exists } " )
185+ V1_REGISTER_VIEW = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .register_view } " )
184186 V1_DELETE_VIEW = Endpoint (http_method = HttpMethod .DELETE , path = f"{ API_PREFIX } /{ Endpoints .drop_view } " )
185187 V1_SUBMIT_TABLE_SCAN_PLAN = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .plan_table_scan } " )
186188 V1_TABLE_SCAN_PLAN_TASKS = Endpoint (http_method = HttpMethod .POST , path = f"{ API_PREFIX } /{ Endpoints .fetch_scan_tasks } " )
@@ -318,6 +320,11 @@ class RegisterTableRequest(IcebergBaseModel):
318320 metadata_location : str = Field (..., alias = "metadata-location" )
319321
320322
323+ class RegisterViewRequest (IcebergBaseModel ):
324+ name : str
325+ metadata_location : str = Field (..., alias = "metadata-location" )
326+
327+
321328class ConfigResponse (IcebergBaseModel ):
322329 defaults : Properties | None = Field (default_factory = dict )
323330 overrides : Properties | None = Field (default_factory = dict )
@@ -1312,6 +1319,27 @@ def view_exists(self, identifier: str | Identifier) -> bool:
13121319
13131320 return False
13141321
1322+ @retry (** _RETRY_ARGS )
1323+ def register_view (self , identifier : str | Identifier , metadata_location : str ) -> View :
1324+ self ._check_endpoint (Capability .V1_REGISTER_VIEW )
1325+ namespace_and_view = self ._split_identifier_for_path (identifier )
1326+ request = RegisterViewRequest (
1327+ name = self ._identifier_to_validated_tuple (identifier )[- 1 ],
1328+ metadata_location = metadata_location ,
1329+ )
1330+ serialized_json = request .model_dump_json ().encode (UTF8 )
1331+ response = self ._session .post (
1332+ self .url (Endpoints .register_view , namespace = namespace_and_view ["namespace" ]),
1333+ data = serialized_json ,
1334+ )
1335+ try :
1336+ response .raise_for_status ()
1337+ except HTTPError as exc :
1338+ _handle_non_200_response (exc , {409 : ViewAlreadyExistsError })
1339+
1340+ view_response = ViewResponse .model_validate_json (response .text )
1341+ return self ._response_to_view (self .identifier_to_tuple (identifier ), view_response )
1342+
13151343 @retry (** _RETRY_ARGS )
13161344 def drop_view (self , identifier : str ) -> None :
13171345 self ._check_endpoint (Capability .V1_DELETE_VIEW )
0 commit comments