This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 07569cc98b [#8625] feat(client-python): add partition oriented
responses (#9096)
07569cc98b is described below
commit 07569cc98b51e21f6ef5e5eec9e359cc50a3e573
Author: George T. C. Lai <[email protected]>
AuthorDate: Fri Nov 14 01:55:42 2025 +0800
[#8625] feat(client-python): add partition oriented responses (#9096)
### What changes were proposed in this pull request?
This PR is aimed at implementing the following Java classes.
- `PartitionResponse`
- `PartitionListResponse`
### Why are the changes needed?
We need to enable table operations in Python client that requires
implementation of the aforementioned methods and classes used in
`RelationalTable`.
Fix: #8625
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Unit tests
---------
Signed-off-by: George T. C. Lai <[email protected]>
---
.../dto/responses/partition_list_response.py | 43 +++++++++++++++++
.../gravitino/dto/responses/partition_response.py | 39 +++++++++++++++
.../tests/unittests/test_responses.py | 55 ++++++++++++++++++++++
3 files changed, 137 insertions(+)
diff --git
a/clients/client-python/gravitino/dto/responses/partition_list_response.py
b/clients/client-python/gravitino/dto/responses/partition_list_response.py
new file mode 100644
index 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.py
new file mode 100644
index 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.py
index 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
ModelResponse
from gravitino.dto.responses.model_version_list_response import
ModelVersionListResponse
from gravitino.dto.responses.model_version_response import ModelVersionResponse
from gravitino.dto.responses.model_version_uri_response import
ModelVersionUriResponse
+from gravitino.dto.responses.partition_list_response import
PartitionListResponse
from gravitino.dto.responses.partition_name_list_response import (
PartitionNameListResponse,
)
+from gravitino.dto.responses.partition_response import PartitionResponse
from gravitino.exceptions.base import IllegalArgumentException
class 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()