This is an automated email from the ASF dual-hosted git repository.
jerryshao 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 1f5cee0770 [#3767] refactor(client-python): Share table test fixtures
(#11992)
1f5cee0770 is described below
commit 1f5cee0770664390f1e30ad4c23db512dde2c651
Author: Henry Chen <[email protected]>
AuthorDate: Thu Jul 16 20:06:11 2026 +0800
[#3767] refactor(client-python): Share table test fixtures (#11992)
### What changes were proposed in this pull request?
This PR refactors duplicated Python client unit test fixtures for
relational table metadata.
The duplicated table and identity partition JSON fixtures are moved into
shared test fixture helpers under
`tests/unittests/fixtures/table_fixtures.py`. Related unit tests now
reuse these shared fixtures instead of embedding large repeated JSON
strings directly in each test file.
### Why are the changes needed?
Several Python client unit tests duplicated the same table and partition
JSON payloads, which contributes to the remaining `duplicate-code`
Pylint violations tracked by #3767.
Centralizing these fixtures makes the tests easier to maintain and
reduces duplicated test data without changing the tested behavior.
Related to #3767.
### Does this PR introduce *any* user-facing change?
No. This change only refactors Python client unit test fixtures.
### How was this patch tested?
```bash
git diff --cached --check
---
.../tests/unittests/dto/rel/test_table_dto.py | 129 +-----------
.../unittests/dto/responses/test_responses.py | 163 +--------------
.../unittests/dto/util/test_dto_converters.py | 129 +-----------
.../tests/unittests/fixtures/__init__.py | 16 ++
.../tests/unittests/fixtures/table_fixtures.py | 222 +++++++++++++++++++++
.../tests/unittests/test_relational_catalog.py | 131 +-----------
.../tests/unittests/test_relational_table.py | 158 +--------------
.../client-python/tests/unittests/test_requests.py | 133 +-----------
8 files changed, 260 insertions(+), 821 deletions(-)
diff --git a/clients/client-python/tests/unittests/dto/rel/test_table_dto.py
b/clients/client-python/tests/unittests/dto/rel/test_table_dto.py
index 271624cee9..293d3935a8 100644
--- a/clients/client-python/tests/unittests/dto/rel/test_table_dto.py
+++ b/clients/client-python/tests/unittests/dto/rel/test_table_dto.py
@@ -35,138 +35,13 @@ from gravitino.dto.rel.partitioning.partitioning import
SingleFieldPartitioning
from gravitino.dto.rel.sort_order_dto import SortOrderDTO
from gravitino.dto.rel.table_dto import TableDTO
from gravitino.exceptions.base import IllegalArgumentException
+from tests.unittests.fixtures.table_fixtures import TABLE_DTO_JSON_STRING
class TestTableDTO(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
- cls.complete_json = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "audit": {
- "creator": "Apache Gravitino",
- "createTime":"2025-10-10T00:00:00"
- },
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "age" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
+ cls.complete_json = TABLE_DTO_JSON_STRING
def test_table_dto_complete_deserialize(self):
dto = TableDTO.from_json(self.complete_json)
diff --git
a/clients/client-python/tests/unittests/dto/responses/test_responses.py
b/clients/client-python/tests/unittests/dto/responses/test_responses.py
index 0971bf8033..ee4e44cc94 100644
--- a/clients/client-python/tests/unittests/dto/responses/test_responses.py
+++ b/clients/client-python/tests/unittests/dto/responses/test_responses.py
@@ -39,168 +39,17 @@ from gravitino.dto.responses.partition_name_list_response
import (
from gravitino.dto.responses.partition_response import PartitionResponse
from gravitino.dto.responses.table_response import TableResponse
from gravitino.exceptions.base import IllegalArgumentException
+from tests.unittests.fixtures.table_fixtures import (
+ IDENTITY_PARTITION_WITH_PROPERTIES_JSON_STRING,
+ TABLE_JSON_STRING_WITH_ANONYMOUS_CREATOR_AND_ID_SORT,
+)
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"
- }
- }
- """
- cls.TABLE_JSON_STRING = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "audit": {
- "creator": "anonymous",
- "createTime":"2025-10-10T00:00:00"
- },
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "id" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
+ cls.PARTITION_JSON_STRING =
IDENTITY_PARTITION_WITH_PROPERTIES_JSON_STRING
+ cls.TABLE_JSON_STRING =
TABLE_JSON_STRING_WITH_ANONYMOUS_CREATOR_AND_ID_SORT
def test_file_location_response(self):
json_data = {"code": 0, "fileLocation": "file:/test/1"}
diff --git
a/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
b/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
index 51ebf0bdd9..3918be7658 100644
--- a/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
+++ b/clients/client-python/tests/unittests/dto/util/test_dto_converters.py
@@ -74,6 +74,7 @@ from gravitino.dto.rel.sort_order_dto import SortOrderDTO
from gravitino.dto.rel.table_dto import TableDTO
from gravitino.dto.util.dto_converters import DTOConverters
from gravitino.exceptions.base import IllegalArgumentException
+from tests.unittests.fixtures.table_fixtures import TABLE_DTO_JSON_STRING
class TestDTOConverters(unittest.TestCase):
@@ -118,133 +119,7 @@ class TestDTOConverters(unittest.TestCase):
Transforms.NAME_OF_HOUR: Transforms.hour("createTime"),
}
- cls.table_dto_json = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "audit": {
- "creator": "Apache Gravitino",
- "createTime":"2025-10-10T00:00:00"
- },
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "age" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
+ cls.table_dto_json = TABLE_DTO_JSON_STRING
def test_from_function_arg_literal_dto(self):
for data_type, value in TestDTOConverters.literals.items():
diff --git a/clients/client-python/tests/unittests/fixtures/__init__.py
b/clients/client-python/tests/unittests/fixtures/__init__.py
new file mode 100644
index 0000000000..13a83393a9
--- /dev/null
+++ b/clients/client-python/tests/unittests/fixtures/__init__.py
@@ -0,0 +1,16 @@
+# 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.
diff --git a/clients/client-python/tests/unittests/fixtures/table_fixtures.py
b/clients/client-python/tests/unittests/fixtures/table_fixtures.py
new file mode 100644
index 0000000000..21b9f9cdf3
--- /dev/null
+++ b/clients/client-python/tests/unittests/fixtures/table_fixtures.py
@@ -0,0 +1,222 @@
+# 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 json
+from typing import Any
+
+
+def _table_columns(include_age_column: bool = False) -> list[dict[str, Any]]:
+ columns = [
+ {
+ "name": "id",
+ "type": "integer",
+ "comment": "id column comment",
+ "nullable": False,
+ "autoIncrement": True,
+ "defaultValue": {
+ "type": "literal",
+ "dataType": "integer",
+ "value": "-1",
+ },
+ },
+ {
+ "name": "name",
+ "type": "varchar(500)",
+ "comment": "name column comment",
+ "nullable": True,
+ "autoIncrement": False,
+ "defaultValue": {
+ "type": "literal",
+ "dataType": "null",
+ "value": "null",
+ },
+ },
+ {
+ "name": "StartingDate",
+ "type": "timestamp",
+ "comment": "StartingDate column comment",
+ "nullable": False,
+ "autoIncrement": False,
+ "defaultValue": {
+ "type": "function",
+ "funcName": "current_timestamp",
+ "funcArgs": [],
+ },
+ },
+ {
+ "name": "info",
+ "type": {
+ "type": "struct",
+ "fields": [
+ {
+ "name": "position",
+ "type": "string",
+ "nullable": True,
+ "comment": "position field comment",
+ },
+ {
+ "name": "contact",
+ "type": {
+ "type": "list",
+ "elementType": "integer",
+ "containsNull": False,
+ },
+ "nullable": True,
+ "comment": "contact field comment",
+ },
+ {
+ "name": "rating",
+ "type": {
+ "type": "map",
+ "keyType": "string",
+ "valueType": "integer",
+ "valueContainsNull": False,
+ },
+ "nullable": True,
+ "comment": "rating field comment",
+ },
+ ],
+ },
+ "comment": "info column comment",
+ "nullable": True,
+ },
+ {
+ "name": "dt",
+ "type": "date",
+ "comment": "dt column comment",
+ "nullable": True,
+ },
+ ]
+
+ if include_age_column:
+ columns.append(
+ {
+ "name": "age",
+ "type": "integer",
+ "comment": "age column comment",
+ "nullable": True,
+ }
+ )
+
+ return columns
+
+
+def table_json(
+ creator: str = "Apache Gravitino",
+ include_age_column: bool = False,
+ include_audit: bool = True,
+ sort_field_name: str = "age",
+) -> str:
+ table_data: dict[str, Any] = {
+ "name": "example_table",
+ "comment": "This is an example table",
+ "columns": _table_columns(include_age_column),
+ "partitioning": [
+ {
+ "strategy": "identity",
+ "fieldName": ["dt"],
+ }
+ ],
+ "distribution": {
+ "strategy": "hash",
+ "number": 32,
+ "funcArgs": [
+ {
+ "type": "field",
+ "fieldName": ["id"],
+ }
+ ],
+ },
+ "sortOrders": [
+ {
+ "sortTerm": {
+ "type": "field",
+ "fieldName": [sort_field_name],
+ },
+ "direction": "asc",
+ "nullOrdering": "nulls_first",
+ }
+ ],
+ "indexes": [
+ {
+ "indexType": "primary_key",
+ "name": "PRIMARY",
+ "fieldNames": [["id"]],
+ }
+ ],
+ "properties": {
+ "format": "ORC",
+ },
+ }
+
+ if include_audit:
+ table_data["audit"] = {
+ "creator": creator,
+ "createTime": "2025-10-10T00:00:00",
+ }
+
+ return json.dumps(table_data, indent=4)
+
+
+def identity_partition_json(
+ field_names: list[list[str]] | None = None,
+ properties: dict[str, str] | None = None,
+) -> str:
+ partition_data: dict[str, Any] = {
+ "type": "identity",
+ "name": "test_identity_partition",
+ "fieldNames": field_names or [["column_name"]],
+ "values": [
+ {
+ "type": "literal",
+ "dataType": "integer",
+ "value": "0",
+ },
+ {
+ "type": "literal",
+ "dataType": "integer",
+ "value": "100",
+ },
+ ],
+ }
+
+ if properties is not None:
+ partition_data["properties"] = properties
+
+ return json.dumps(partition_data, indent=4)
+
+
+TABLE_DTO_JSON_STRING = table_json()
+TABLE_DTO_JSON_STRING_WITH_STARTING_DATE_SORT = table_json(
+ sort_field_name="StartingDate"
+)
+TABLE_JSON_STRING_WITH_ANONYMOUS_CREATOR_AND_ID_SORT = table_json(
+ creator="anonymous",
+ sort_field_name="id",
+)
+TABLE_CREATE_REQUEST_JSON_STRING = table_json(
+ include_age_column=True,
+ include_audit=False,
+)
+IDENTITY_PARTITION_JSON_STRING = identity_partition_json()
+IDENTITY_PARTITION_WITH_PROPERTIES_JSON_STRING = identity_partition_json(
+ field_names=[["upper"], ["lower"]],
+ properties={
+ "key1": "value1",
+ "key2": "value2",
+ },
+)
diff --git a/clients/client-python/tests/unittests/test_relational_catalog.py
b/clients/client-python/tests/unittests/test_relational_catalog.py
index abb80509b9..4a9fbecc71 100644
--- a/clients/client-python/tests/unittests/test_relational_catalog.py
+++ b/clients/client-python/tests/unittests/test_relational_catalog.py
@@ -37,6 +37,9 @@ from gravitino.exceptions.base import (
from gravitino.name_identifier import NameIdentifier
from gravitino.namespace import Namespace
from gravitino.utils import HTTPClient, Response
+from tests.unittests.fixtures.table_fixtures import (
+ TABLE_DTO_JSON_STRING_WITH_STARTING_DATE_SORT,
+)
class TestRelationalCatalog(unittest.TestCase):
@@ -57,133 +60,7 @@ class TestRelationalCatalog(unittest.TestCase):
audit=AuditDTO("anonymous"),
rest_client=cls.rest_client,
)
- cls.TABLE_DTO_JSON_STRING = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "audit": {
- "creator": "Apache Gravitino",
- "createTime":"2025-10-10T00:00:00"
- },
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "StartingDate" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
+ cls.TABLE_DTO_JSON_STRING =
TABLE_DTO_JSON_STRING_WITH_STARTING_DATE_SORT
cls.table_dto = TableDTO.from_json(cls.TABLE_DTO_JSON_STRING)
def _get_mock_http_resp(self, json_str: str, return_code: int = 200):
diff --git a/clients/client-python/tests/unittests/test_relational_table.py
b/clients/client-python/tests/unittests/test_relational_table.py
index 056b1e7c53..7b20c1ea7f 100644
--- a/clients/client-python/tests/unittests/test_relational_table.py
+++ b/clients/client-python/tests/unittests/test_relational_table.py
@@ -44,163 +44,17 @@ from gravitino.dto.responses.partition_name_list_response
import (
from gravitino.dto.responses.partition_response import PartitionResponse
from gravitino.namespace import Namespace
from gravitino.utils import HTTPClient, Response
+from tests.unittests.fixtures.table_fixtures import (
+ IDENTITY_PARTITION_JSON_STRING,
+ TABLE_DTO_JSON_STRING,
+)
class TestRelationalTable(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
- cls.TABLE_DTO_JSON_STRING = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "audit": {
- "creator": "Apache Gravitino",
- "createTime":"2025-10-10T00:00:00"
- },
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "age" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
-
- cls.PARTITION_JSON_STRING = """
- {
- "type": "identity",
- "name": "test_identity_partition",
- "fieldNames": [
- [
- "column_name"
- ]
- ],
- "values": [
- {
- "type": "literal",
- "dataType": "integer",
- "value": "0"
- },
- {
- "type": "literal",
- "dataType": "integer",
- "value": "100"
- }
- ]
- }
- """
-
+ cls.TABLE_DTO_JSON_STRING = TABLE_DTO_JSON_STRING
+ cls.PARTITION_JSON_STRING = IDENTITY_PARTITION_JSON_STRING
cls.table_dto = TableDTO.from_json(cls.TABLE_DTO_JSON_STRING)
cls.namespace = Namespace.of("metalake_demo", "test_catalog",
"test_schema")
cls.rest_client = HTTPClient("http://localhost:8090")
diff --git a/clients/client-python/tests/unittests/test_requests.py
b/clients/client-python/tests/unittests/test_requests.py
index 4d1f047e3b..c200a7026c 100644
--- a/clients/client-python/tests/unittests/test_requests.py
+++ b/clients/client-python/tests/unittests/test_requests.py
@@ -38,6 +38,7 @@ from gravitino.dto.requests.function_update_request import (
from gravitino.dto.requests.function_updates_request import
FunctionUpdatesRequest
from gravitino.dto.requests.table_create_request import TableCreateRequest
from gravitino.exceptions.base import IllegalArgumentException
+from tests.unittests.fixtures.table_fixtures import
TABLE_CREATE_REQUEST_JSON_STRING
class TestRequests(unittest.TestCase):
@@ -109,137 +110,7 @@ class TestRequests(unittest.TestCase):
req.validate()
def test_table_create_request(self):
- json_str = """
- {
- "name": "example_table",
- "comment": "This is an example table",
- "columns": [
- {
- "name": "id",
- "type": "integer",
- "comment": "id column comment",
- "nullable": false,
- "autoIncrement": true,
- "defaultValue": {
- "type": "literal",
- "dataType": "integer",
- "value": "-1"
- }
- },
- {
- "name": "name",
- "type": "varchar(500)",
- "comment": "name column comment",
- "nullable": true,
- "autoIncrement": false,
- "defaultValue": {
- "type": "literal",
- "dataType": "null",
- "value": "null"
- }
- },
- {
- "name": "StartingDate",
- "type": "timestamp",
- "comment": "StartingDate column comment",
- "nullable": false,
- "autoIncrement": false,
- "defaultValue": {
- "type": "function",
- "funcName": "current_timestamp",
- "funcArgs": []
- }
- },
- {
- "name": "info",
- "type": {
- "type": "struct",
- "fields": [
- {
- "name": "position",
- "type": "string",
- "nullable": true,
- "comment": "position field comment"
- },
- {
- "name": "contact",
- "type": {
- "type": "list",
- "elementType": "integer",
- "containsNull": false
- },
- "nullable": true,
- "comment": "contact field comment"
- },
- {
- "name": "rating",
- "type": {
- "type": "map",
- "keyType": "string",
- "valueType": "integer",
- "valueContainsNull": false
- },
- "nullable": true,
- "comment": "rating field comment"
- }
- ]
- },
- "comment": "info column comment",
- "nullable": true
- },
- {
- "name": "dt",
- "type": "date",
- "comment": "dt column comment",
- "nullable": true
- },
- {
- "name": "age",
- "type": "integer",
- "comment": "age column comment",
- "nullable": true
- }
- ],
- "partitioning": [
- {
- "strategy": "identity",
- "fieldName": [ "dt" ]
- }
- ],
- "distribution": {
- "strategy": "hash",
- "number": 32,
- "funcArgs": [
- {
- "type": "field",
- "fieldName": [ "id" ]
- }
- ]
- },
- "sortOrders": [
- {
- "sortTerm": {
- "type": "field",
- "fieldName": [ "age" ]
- },
- "direction": "asc",
- "nullOrdering": "nulls_first"
- }
- ],
- "indexes": [
- {
- "indexType": "primary_key",
- "name": "PRIMARY",
- "fieldNames": [["id"]]
- }
- ],
- "properties": {
- "format": "ORC"
- }
- }
- """
-
- req = TableCreateRequest.from_json(json_str)
+ req = TableCreateRequest.from_json(TABLE_CREATE_REQUEST_JSON_STRING)
req.validate()
multiple_auto_increment_json_str = """