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


##########
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:
   I think we can reuse the method `check_string_not_empty` in 
`gravitino.utils.preconditions.Precondition`



##########
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."""

Review Comment:
   These are declared here as class variables instead of instance ones. I think 
we should remove them all.



##########
clients/client-python/gravitino/dto/requests/tags_associate_request.py:
##########
@@ -0,0 +1,70 @@
+# 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.
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+from typing import List, Optional
+
+from dataclasses_json import config
+
+from gravitino.rest.rest_message import RESTRequest
+
+
+@dataclass
+class TagsAssociateRequest(RESTRequest):
+    """Represents a request to associate tags with a metadata object."""
+
+    _tags_to_add: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToAdd")
+    )
+    _tags_to_remove: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToRemove")
+    )
+
+    def __init__(
+        self,
+        tags_to_add: Optional[List[str]] = None,
+        tags_to_remove: Optional[List[str]] = None,
+    ) -> None:
+        self._tags_to_add = tags_to_add
+        self._tags_to_remove = tags_to_remove
+
+    def validate(self) -> None:
+        """Validates the request.
+
+        Raises:
+            ValueError: If both tags_to_add and tags_to_remove are None.
+        """
+        if self._tags_to_add is None and self._tags_to_remove is None:
+            raise ValueError(
+                "tags_to_add and tags_to_remove cannot both be null"
+            )

Review Comment:
   We can reuse `check_aregument` in `gravition.utils.precondition`.



##########
clients/client-python/gravitino/dto/requests/tags_associate_request.py:
##########
@@ -0,0 +1,70 @@
+# 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.
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+from typing import List, Optional
+
+from dataclasses_json import config
+
+from gravitino.rest.rest_message import RESTRequest
+
+
+@dataclass
+class TagsAssociateRequest(RESTRequest):
+    """Represents a request to associate tags with a metadata object."""
+
+    _tags_to_add: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToAdd")
+    )
+    _tags_to_remove: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToRemove")
+    )
+
+    def __init__(
+        self,
+        tags_to_add: Optional[List[str]] = None,
+        tags_to_remove: Optional[List[str]] = None,
+    ) -> None:
+        self._tags_to_add = tags_to_add
+        self._tags_to_remove = tags_to_remove
+
+    def validate(self) -> None:
+        """Validates the request.
+
+        Raises:
+            ValueError: If both tags_to_add and tags_to_remove are None.
+        """
+        if self._tags_to_add is None and self._tags_to_remove is None:
+            raise ValueError(
+                "tags_to_add and tags_to_remove cannot both be null"
+            )
+
+        if self._tags_to_add is not None:
+            for tag in self._tags_to_add:
+                if not tag or not tag.strip():
+                    raise ValueError(
+                        "tags_to_add must not contain null or empty tag names"
+                    )

Review Comment:
   Similarly, reuse `precondition`.



##########
clients/client-python/gravitino/dto/requests/tags_associate_request.py:
##########
@@ -0,0 +1,70 @@
+# 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.
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+from typing import List, Optional
+
+from dataclasses_json import config
+
+from gravitino.rest.rest_message import RESTRequest
+
+
+@dataclass
+class TagsAssociateRequest(RESTRequest):
+    """Represents a request to associate tags with a metadata object."""
+
+    _tags_to_add: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToAdd")
+    )
+    _tags_to_remove: Optional[List[str]] = field(
+        default=None, metadata=config(field_name="tagsToRemove")
+    )
+
+    def __init__(
+        self,
+        tags_to_add: Optional[List[str]] = None,
+        tags_to_remove: Optional[List[str]] = None,
+    ) -> None:
+        self._tags_to_add = tags_to_add
+        self._tags_to_remove = tags_to_remove
+
+    def validate(self) -> None:
+        """Validates the request.
+
+        Raises:
+            ValueError: If both tags_to_add and tags_to_remove are None.
+        """
+        if self._tags_to_add is None and self._tags_to_remove is None:
+            raise ValueError(
+                "tags_to_add and tags_to_remove cannot both be null"
+            )
+
+        if self._tags_to_add is not None:
+            for tag in self._tags_to_add:
+                if not tag or not tag.strip():
+                    raise ValueError(
+                        "tags_to_add must not contain null or empty tag names"
+                    )
+
+        if self._tags_to_remove is not None:
+            for tag in self._tags_to_remove:
+                if not tag or not tag.strip():
+                    raise ValueError(
+                        "tags_to_remove must not contain null or empty tag 
names"
+                    )

Review Comment:
   Similarly, reuse `precondition`.



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