World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8625] feat(client-python): add partition oriented responses (#9096)
George T. C. Lai07569cc98b51
diff --git a/clients/client-python/gravitino/dto/responses/partition_list_response.py b/clients/client-python/gravitino/dto/responses/partition_list_response.pynew file mode 100644index 0000000000..084871fe16--- /dev/null+++ b/clients/client-python/gravitino/dto/responses/partition_list_response.py@@ -0,0 +1,43 @@+# 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 dataclasses import dataclass, field++from dataclasses_json import config++from gravitino.dto.rel.partitions.json_serdes.partition_dto_serdes import (+ PartitionDTOSerdes,+)+from gravitino.dto.rel.partitions.partition_dto import PartitionDTO+from gravitino.dto.responses.base_response import BaseResponse+++@dataclass+class PartitionListResponse(BaseResponse):+ """Represents a response for a list of partitions."""++ _partitions: list[PartitionDTO] = field(+ metadata=config(+ field_name="partitions",+ decoder=lambda partitions: [+ PartitionDTOSerdes.deserialize(partition) for partition in partitions+ ],+ encoder=lambda partitions: [+ PartitionDTOSerdes.serialize(partition) for partition in partitions+ ],+ )+ )diff --git a/clients/client-python/gravitino/dto/responses/partition_response.py b/clients/client-python/gravitino/dto/responses/partition_response.pynew file mode 100644index 0000000000..b6a0117cf7--- /dev/null+++ b/clients/client-python/gravitino/dto/responses/partition_response.py@@ -0,0 +1,39 @@+# 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 dataclasses import dataclass, field++from dataclasses_json import config++from gravitino.dto.rel.partitions.json_serdes.partition_dto_serdes import (+ PartitionDTOSerdes,+)+from gravitino.dto.rel.partitions.partition_dto import PartitionDTO+from gravitino.dto.responses.base_response import BaseResponse+++@dataclass+class PartitionResponse(BaseResponse):+ """Represents a response for a partition."""++ _partition: PartitionDTO = field(+ metadata=config(+ field_name="partition",+ decoder=PartitionDTOSerdes.deserialize,+ encoder=PartitionDTOSerdes.serialize,+ )+ )diff --git a/clients/client-python/tests/unittests/test_responses.py b/clients/client-python/tests/unittests/test_responses.pyindex 423a87acfa..b6783cb959 100644--- a/clients/client-python/tests/unittests/test_responses.py+++ b/clients/client-python/tests/unittests/test_responses.py@@ -23,13 +23,48 @@ from gravitino.dto.responses.model_response import ModelResponsefrom gravitino.dto.responses.model_version_list_response import ModelVersionListResponsefrom gravitino.dto.responses.model_version_response import ModelVersionResponsefrom gravitino.dto.responses.model_version_uri_response import ModelVersionUriResponse+from gravitino.dto.responses.partition_list_response import PartitionListResponsefrom gravitino.dto.responses.partition_name_list_response import (PartitionNameListResponse,)+from gravitino.dto.responses.partition_response import PartitionResponsefrom gravitino.exceptions.base import IllegalArgumentExceptionclass TestResponses(unittest.TestCase):+ @classmethod+ def setUpClass(cls) -> None:+ cls.PARTITION_JSON_STRING = """+ {+ "type": "identity",+ "name": "test_identity_partition",+ "fieldNames": [+ [+ "upper"+ ],+ [+ "lower"+ ]+ ],+ "values": [+ {+ "type": "literal",+ "dataType": "integer",+ "value": "0"+ },+ {+ "type": "literal",+ "dataType": "integer",+ "value": "100"+ }+ ],+ "properties": {+ "key1": "value1",+ "key2": "value2"+ }+ }+ """+def test_file_location_response(self):json_data = {"code": 0, "fileLocation": "file:/test/1"}json_str = json.dumps(json_data)@@ -293,3 +328,23 @@ class TestResponses(unittest.TestCase):resp: PartitionNameListResponse = PartitionNameListResponse.from_json(json_str)with self.assertRaises(IllegalArgumentException):resp.validate()++ def test_partition_response(self):+ json_string = f"""+ {{+ "code": 0,+ "partition": {TestResponses.PARTITION_JSON_STRING}+ }}+ """+ resp: PartitionResponse = PartitionResponse.from_json(json_string)+ resp.validate()++ def test_partition_list_response(self):+ json_string = f"""+ {{+ "code": 0,+ "partitions": [{TestResponses.PARTITION_JSON_STRING}]+ }}+ """+ resp: PartitionListResponse = PartitionListResponse.from_json(json_string)+ resp.validate()