This is an automated email from the ASF dual-hosted git repository. lzljs3620320 pushed a commit to branch release-1.3 in repository https://gitbox.apache.org/repos/asf/paimon.git
commit f97750d1962b71dd94c8a9a2c85ee3334972af31 Author: universe-hcy <[email protected]> AuthorDate: Tue Nov 4 15:39:14 2025 +0800 [Python] Keep the variable names of Identifier consistent with Java (#6520) --- paimon-python/pypaimon/api/rest_api.py | 16 ++++++------- paimon-python/pypaimon/common/identifier.py | 26 +++++++++++----------- paimon-python/pypaimon/schema/data_types.py | 6 ++--- .../pypaimon/snapshot/catalog_snapshot_commit.py | 6 ++--- paimon-python/pypaimon/tests/rest/rest_server.py | 18 +++++++++------ 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/paimon-python/pypaimon/api/rest_api.py b/paimon-python/pypaimon/api/rest_api.py old mode 100644 new mode 100755 index 037a531e58..d715c8a4aa --- a/paimon-python/pypaimon/api/rest_api.py +++ b/paimon-python/pypaimon/api/rest_api.py @@ -219,15 +219,15 @@ class RESTApi: def create_table(self, identifier: Identifier, schema: Schema) -> None: request = CreateTableRequest(identifier, schema) return self.client.post( - self.resource_paths.tables(identifier.database_name), + self.resource_paths.tables(identifier.get_database_name()), request, self.rest_auth_function) def get_table(self, identifier: Identifier) -> GetTableResponse: return self.client.get( self.resource_paths.table( - identifier.database_name, - identifier.object_name), + identifier.get_database_name(), + identifier.get_object_name()), GetTableResponse, self.rest_auth_function, ) @@ -235,8 +235,8 @@ class RESTApi: def drop_table(self, identifier: Identifier) -> GetTableResponse: return self.client.delete( self.resource_paths.table( - identifier.database_name, - identifier.object_name), + identifier.get_database_name(), + identifier.get_object_name()), self.rest_auth_function, ) @@ -250,8 +250,8 @@ class RESTApi: def load_table_token(self, identifier: Identifier) -> GetTableTokenResponse: return self.client.get( self.resource_paths.table_token( - identifier.database_name, - identifier.object_name), + identifier.get_database_name(), + identifier.get_object_name()), GetTableTokenResponse, self.rest_auth_function, ) @@ -282,7 +282,7 @@ class RESTApi: request = CommitTableRequest(table_uuid, snapshot, statistics) response = self.client.post_with_response_type( self.resource_paths.commit_table( - identifier.database_name, identifier.object_name), + identifier.get_database_name(), identifier.get_object_name()), request, CommitTableResponse, self.rest_auth_function diff --git a/paimon-python/pypaimon/common/identifier.py b/paimon-python/pypaimon/common/identifier.py old mode 100644 new mode 100755 index 0731db50db..6851a18074 --- a/paimon-python/pypaimon/common/identifier.py +++ b/paimon-python/pypaimon/common/identifier.py @@ -27,13 +27,13 @@ SYSTEM_BRANCH_PREFIX = 'branch-' @dataclass class Identifier: - database_name: str = json_field("database", default=None) - object_name: str = json_field("object", default=None) - branch_name: Optional[str] = json_field("branch", default=None) + database: str = json_field("database", default=None) + object: str = json_field("object", default=None) + branch: Optional[str] = json_field("branch", default=None) @classmethod - def create(cls, database_name: str, object_name: str) -> "Identifier": - return cls(database_name, object_name) + def create(cls, database: str, object: str) -> "Identifier": + return cls(database, object) @classmethod def from_string(cls, full_name: str) -> "Identifier": @@ -46,21 +46,21 @@ class Identifier: raise ValueError("Invalid identifier format: {}".format(full_name)) def get_full_name(self) -> str: - if self.branch_name: - return "{}.{}.{}".format(self.database_name, self.object_name, self.branch_name) - return "{}.{}".format(self.database_name, self.object_name) + if self.branch: + return "{}.{}.{}".format(self.database, self.object, self.branch) + return "{}.{}".format(self.database, self.object) def get_database_name(self) -> str: - return self.database_name + return self.database def get_table_name(self) -> str: - return self.object_name + return self.object def get_object_name(self) -> str: - return self.object_name + return self.object def get_branch_name(self) -> Optional[str]: - return self.branch_name + return self.branch def is_system_table(self) -> bool: - return self.object_name.startswith('$') + return self.object.startswith('$') diff --git a/paimon-python/pypaimon/schema/data_types.py b/paimon-python/pypaimon/schema/data_types.py old mode 100644 new mode 100755 index c65771d7f2..3f7b30c291 --- a/paimon-python/pypaimon/schema/data_types.py +++ b/paimon-python/pypaimon/schema/data_types.py @@ -73,10 +73,8 @@ class AtomicType(DataType): super().__init__(nullable) self.type = type - def to_dict(self) -> str: - if not self.nullable: - return self.type + " NOT NULL" - return self.type + def to_dict(self) -> Dict[str, Any]: + return {"type": self.type if self.nullable else self.type + " NOT NULL"} @classmethod def from_dict(cls, data: str) -> "AtomicType": diff --git a/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py b/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py old mode 100644 new mode 100755 index 26796f7766..1ffc80af57 --- a/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py +++ b/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py @@ -57,9 +57,9 @@ class CatalogSnapshotCommit(SnapshotCommit): Exception: If commit fails """ new_identifier = Identifier( - database_name=self.identifier.get_database_name(), - object_name=self.identifier.get_table_name(), - branch_name=branch + database=self.identifier.get_database_name(), + object=self.identifier.get_table_name(), + branch=branch ) # Call catalog's commit_snapshot method diff --git a/paimon-python/pypaimon/tests/rest/rest_server.py b/paimon-python/pypaimon/tests/rest/rest_server.py old mode 100644 new mode 100755 index d2908e59be..1970b79dd0 --- a/paimon-python/pypaimon/tests/rest/rest_server.py +++ b/paimon-python/pypaimon/tests/rest/rest_server.py @@ -253,9 +253,9 @@ class RESTCatalogServer: source = self.table_metadata_store.get(source_table.get_full_name()) self.table_metadata_store.update({destination_table.get_full_name(): source}) source_table_dir = (Path(self.data_path) / self.warehouse - / source_table.database_name / source_table.object_name) + / source_table.get_database_name() / source_table.get_object_name()) destination_table_dir = (Path(self.data_path) / self.warehouse - / destination_table.database_name / destination_table.object_name) + / destination_table.get_database_name() / destination_table.get_object_name()) if not source_table_dir.exists(): destination_table_dir.mkdir(parents=True) else: @@ -352,7 +352,7 @@ class RESTCatalogServer: table_name_part = table_parts[0] branch_part = table_parts[1] # Recreate identifier without branch for lookup - lookup_identifier = Identifier.create(identifier.database_name, table_name_part) + lookup_identifier = Identifier.create(identifier.get_database_name(), table_name_part) else: lookup_identifier = identifier branch_part = None @@ -431,8 +431,10 @@ class RESTCatalogServer: create_table.identifier, 0, create_table.schema, str(uuid.uuid4()), False ) self.table_metadata_store.update({create_table.identifier.get_full_name(): table_metadata}) - table_dir = Path( - self.data_path) / self.warehouse / database_name / create_table.identifier.object_name / 'schema' + table_dir = ( + Path(self.data_path) / self.warehouse / database_name / + create_table.identifier.get_object_name() / 'schema' + ) if not table_dir.exists(): table_dir.mkdir(parents=True) with open(table_dir / "schema-0", "w") as f: @@ -446,7 +448,8 @@ class RESTCatalogServer: if identifier.get_full_name() not in self.table_metadata_store: raise TableNotExistException(identifier) table_metadata = self.table_metadata_store[identifier.get_full_name()] - table_path = f'file://{self.data_path}/{self.warehouse}/{identifier.database_name}/{identifier.object_name}' + table_path = (f'file://{self.data_path}/{self.warehouse}/' + f'{identifier.get_database_name()}/{identifier.get_object_name()}') schema = table_metadata.schema.to_schema() response = self.mock_table(identifier, table_metadata, table_path, schema) return self._mock_response(response, 200) @@ -522,7 +525,8 @@ class RESTCatalogServer: import uuid # Construct table path: {warehouse}/{database}/{table} - table_path = os.path.join(self.data_path, self.warehouse, identifier.database_name, identifier.object_name) + table_path = os.path.join(self.data_path, self.warehouse, identifier.get_database_name(), + identifier.get_object_name()) # Create directory structure snapshot_dir = os.path.join(table_path, "snapshot")
