From bc2f6e319495975dbb43f55dd45295ba80528bf3 Mon Sep 17 00:00:00 2001 From: "chuyu.hcy" Date: Mon, 3 Nov 2025 17:57:00 +0800 Subject: [PATCH] [Python] Keep the variable names of Identifier consistent with Java --- paimon-python/pypaimon/api/rest_api.py | 16 ++++++------ paimon-python/pypaimon/common/identifier.py | 26 +++++++++---------- paimon-python/pypaimon/schema/data_types.py | 6 ++--- .../snapshot/catalog_snapshot_commit.py | 6 ++--- .../pypaimon/tests/rest/rest_server.py | 18 ++++++++----- 5 files changed, 37 insertions(+), 35 deletions(-) mode change 100644 => 100755 paimon-python/pypaimon/api/rest_api.py mode change 100644 => 100755 paimon-python/pypaimon/common/identifier.py mode change 100644 => 100755 paimon-python/pypaimon/schema/data_types.py mode change 100644 => 100755 paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py mode change 100644 => 100755 paimon-python/pypaimon/tests/rest/rest_server.py 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 037a531e58f0..d715c8a4aaf8 --- a/paimon-python/pypaimon/api/rest_api.py +++ b/paimon-python/pypaimon/api/rest_api.py @@ -219,15 +219,15 @@ def list_tables_paged( 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 @@ def get_table(self, identifier: Identifier) -> GetTableResponse: 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 @@ def rename_table(self, source_identifier: Identifier, target_identifier: Identif 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 @@ def commit_snapshot( 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 0731db50db99..6851a180741a --- a/paimon-python/pypaimon/common/identifier.py +++ b/paimon-python/pypaimon/common/identifier.py @@ -27,13 +27,13 @@ @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 @@ def from_string(cls, full_name: str) -> "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 c65771d7f26b..3f7b30c29195 --- a/paimon-python/pypaimon/schema/data_types.py +++ b/paimon-python/pypaimon/schema/data_types.py @@ -73,10 +73,8 @@ def __init__(self, type: str, nullable: bool = True): 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 26796f77668a..1ffc80af57b5 --- a/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py +++ b/paimon-python/pypaimon/snapshot/catalog_snapshot_commit.py @@ -57,9 +57,9 @@ def commit(self, snapshot: Snapshot, branch: str, statistics: List[PartitionStat 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 d2908e59be02..1970b79dd067 --- a/paimon-python/pypaimon/tests/rest/rest_server.py +++ b/paimon-python/pypaimon/tests/rest/rest_server.py @@ -253,9 +253,9 @@ def _route_request(self, method: str, resource_path: str, parameters: Dict[str, 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 @@ def _handle_table_resource(self, method: str, path_parts: List[str], 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 @@ def _tables_handle(self, method: str = None, data: str = None, database_name: st 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 @@ def _table_handle(self, method: str, data: str, identifier: Identifier) -> Tuple 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 @@ def _write_snapshot_files(self, identifier: Identifier, snapshot, statistics): 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")