sunyuhan1998 commented on code in PR #10760:
URL: https://github.com/apache/gravitino/pull/10760#discussion_r3090431630


##########
clients/client-python/gravitino/client/metadata_object_tag_operations.py:
##########
@@ -0,0 +1,149 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import logging
+from typing import List
+
+from gravitino.api.metadata_object import MetadataObject
+from gravitino.api.tag.supports_tags import SupportsTags
+from gravitino.api.tag.tag import Tag
+from gravitino.client.generic_tag import GenericTag
+from gravitino.dto.requests.tags_associate_request import TagsAssociateRequest
+from gravitino.dto.responses.tag_response import (
+    TagListResponse,
+    TagNamesListResponse,
+    TagResponse,
+)
+from gravitino.dto.tag_dto import TagDTO
+from gravitino.exceptions.handlers.tag_error_handler import TAG_ERROR_HANDLER
+from gravitino.rest.rest_utils import encode_string
+from gravitino.utils import HTTPClient
+
+logger = logging.getLogger(__name__)
+
+
+class MetadataObjectTagOperations(SupportsTags):
+    """Operations for managing tags on a specific metadata object (e.g., 
Fileset)."""
+
+    _rest_client: HTTPClient
+    """The REST client to communicate with the REST server."""
+
+    _request_path: str
+    """The REST API path for tag operations on this metadata object."""
+
+    _metalake_name: str
+    """The metalake name used to construct GenericTag instances."""
+
+    def __init__(
+        self,
+        metalake_name: str,
+        metadata_object: MetadataObject,
+        rest_client: HTTPClient,
+    ):
+        self._rest_client = rest_client
+        self._metalake_name = metalake_name
+        metadata_object_type = metadata_object.type().value
+        metadata_object_fullname = metadata_object.full_name()
+        self._request_path = (
+            
f"api/metalakes/{encode_string(metalake_name)}/objects/{metadata_object_type}/"
+            f"{encode_string(metadata_object_fullname)}/tags"
+        )
+
+    def list_tags(self) -> List[str]:
+        """List all tag names associated with this metadata object.
+
+        Returns:
+            A list of tag names.
+        """
+        resp = self._rest_client.get(
+            self._request_path, error_handler=TAG_ERROR_HANDLER
+        )
+        tags_resp = TagNamesListResponse.from_json(resp.body, 
infer_missing=True)
+        tags_resp.validate()
+        return tags_resp.tag_names()
+
+    def list_tags_info(self) -> List[Tag]:
+        """List all tags with details associated with this metadata object.
+
+        Returns:
+            A list of Tag objects with full details.
+        """
+        resp = self._rest_client.get(
+            self._request_path,
+            params={"details": "true"},
+            error_handler=TAG_ERROR_HANDLER,
+        )
+        tags_resp = TagListResponse.from_json(resp.body, infer_missing=True)
+        tags_resp.validate()
+        return [
+            self._to_tag(tag_dto) for tag_dto in tags_resp.tags()
+        ]
+
+    def get_tag(self, name: str) -> Tag:
+        """Get a tag by name associated with this metadata object.
+
+        Args:
+            name: The tag name.
+
+        Returns:
+            The Tag object.
+        """
+        if not name or not name.strip():
+            raise ValueError("Tag name must not be null or empty")

Review Comment:
   Thanks, it's done.
   



-- 
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]

Reply via email to