tsungchih commented on code in PR #10554:
URL: https://github.com/apache/gravitino/pull/10554#discussion_r3005882718
##########
clients/client-python/gravitino/client/dto_converters.py:
##########
@@ -285,3 +291,44 @@ def to_job_template_update_request(
return UpdateJobTemplateContentRequest(template_update_dto)
raise ValueError(f"Unknown change type: {type(change).__name__}")
+
+ @staticmethod
+ def to_tag_update_request(
+ change: TagChange,
+ ) -> tp.Union[
+ TagUpdateRequest.RenameTagRequest,
+ TagUpdateRequest.UpdateTagCommentRequest,
+ TagUpdateRequest.SetTagPropertyRequest,
+ TagUpdateRequest.RemoveTagPropertyRequest,
+ ]:
+ """
+ Convert the tag change to the corresponding tag update request.
+
+ Args:
+ change (TagChange): The tag change.
+
+ Raises:
+ ValueError: if the change type is not supported.
+
+ Returns:
+ tp.Union[ TagUpdateRequest.RenameTagRequest,
+ TagUpdateRequest.UpdateTagCommentRequest,
+ TagUpdateRequest.SetTagPropertyRequest,
+ TagUpdateRequest.RemoveTagPropertyRequest,
+ ]: The tag update request.
+ """
+ if isinstance(change, TagChange.RenameTag):
+ return TagUpdateRequest.RenameTagRequest(change.new_name)
+
+ if isinstance(change, TagChange.UpdateTagComment):
+ return TagUpdateRequest.UpdateTagCommentRequest(change.new_comment)
+
+ if isinstance(change, TagChange.SetProperty):
+ return TagUpdateRequest.SetTagPropertyRequest(
+ change.name,
+ change.value,
+ )
+ if isinstance(change, TagChange.RemoveProperty):
+ return
TagUpdateRequest.RemoveTagPropertyRequest(change.removed_property)
+
+ raise ValueError(f"Unknown change type: {type(change)}")
Review Comment:
We should raise the similar exception to the Java client,
`IllegalArgumentException`.
##########
clients/client-python/gravitino/client/dto_converters.py:
##########
@@ -285,3 +291,44 @@ def to_job_template_update_request(
return UpdateJobTemplateContentRequest(template_update_dto)
raise ValueError(f"Unknown change type: {type(change).__name__}")
+
+ @staticmethod
+ def to_tag_update_request(
+ change: TagChange,
+ ) -> tp.Union[
+ TagUpdateRequest.RenameTagRequest,
+ TagUpdateRequest.UpdateTagCommentRequest,
+ TagUpdateRequest.SetTagPropertyRequest,
+ TagUpdateRequest.RemoveTagPropertyRequest,
+ ]:
Review Comment:
All of the four requests are subclasses of `TagUpdateRequestBase`. I think
we can define the return type as the base class.
##########
clients/client-python/gravitino/client/gravitino_metalake.py:
##########
@@ -623,8 +641,31 @@ def alter_tag(self, tag_name, *changes) -> Tag:
NoSuchTagException: If the tag does not exist.
NoSuchMetalakeException: If the metalake does not exist.
"""
- # TODO implement alter_tag
- raise NotImplementedError()
+ Precondition.check_argument(
+ StringUtils.is_not_blank(tag_name),
+ "tag name must not be null or empty",
+ )
+ updates = [DTOConverters.to_tag_update_request(change) for change in
changes]
+ update_req = TagUpdatesRequest(updates)
+ update_req.validate()
+
+ url = self.API_METALAKES_TAG_PATH.format(
+ encode_string(self.name()), encode_string(tag_name)
+ )
+ response = self.rest_client.post(
+ url,
+ json=update_req,
+ error_handler=TAG_ERROR_HANDLER,
+ )
+ tag_resp: TagResponse = TagResponse.from_json(response.body,
infer_missing=True)
+ tag_resp.validate()
+
+ tag_resp.validate()
Review Comment:
Is this statement, `tag_resp,validate()` redundant?
##########
clients/client-python/gravitino/client/gravitino_metalake.py:
##########
@@ -544,8 +550,20 @@ def list_tags_info(self) -> List[Tag]:
Raises:
NoSuchMetalakeException: If the metalake does not exist.
"""
- # TODO implement list_tags_info
- raise NotImplementedError()
+ url = self.API_METALAKES_TAGS_PATH.format(encode_string(self.name()))
+
+ response = self.rest_client.get(url, error_handler=TAG_ERROR_HANDLER)
Review Comment:
I didn't see that parameters are sent with the API call similar to the Java
client.
https://github.com/apache/gravitino/blob/366f3ee4c2a65616faea56c3a8d22b6965922f89/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoMetalake.java#L461-L469
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]