From 428b894aacb107547ba41433b4b6f37e1ad1914a Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Fri, 8 Mar 2024 21:52:12 -0800 Subject: [PATCH] properties validator --- pyiceberg/catalog/rest.py | 7 +++++-- pyiceberg/table/__init__.py | 2 +- pyiceberg/table/metadata.py | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pyiceberg/catalog/rest.py b/pyiceberg/catalog/rest.py index c401339e18..a5f33f02dd 100644 --- a/pyiceberg/catalog/rest.py +++ b/pyiceberg/catalog/rest.py @@ -149,9 +149,12 @@ class CreateTableRequest(IcebergBaseModel): partition_spec: Optional[PartitionSpec] = Field(alias="partition-spec") write_order: Optional[SortOrder] = Field(alias="write-order") stage_create: bool = Field(alias="stage-create", default=False) - properties: Properties = Field(default_factory=dict) + properties: Dict[str, str] = Field(default_factory=dict) + # validators - transform_properties_dict_value_to_str = field_validator('properties', mode='before')(transform_dict_value_to_str) + @field_validator('properties', mode='before') + def transform_properties_dict_value_to_str(cls, properties: Properties) -> Dict[str, str]: + return transform_dict_value_to_str(properties) class RegisterTableRequest(IcebergBaseModel): diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index bb3b7afe33..76aa533d7c 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -473,7 +473,7 @@ class SetLocationUpdate(TableUpdate): class SetPropertiesUpdate(TableUpdate): action: TableUpdateAction = TableUpdateAction.set_properties - updates: Properties + updates: Dict[str, str] @field_validator('updates', mode='before') def transform_properties_dict_value_to_str(cls, properties: Properties) -> Dict[str, str]: diff --git a/pyiceberg/table/metadata.py b/pyiceberg/table/metadata.py index 1e5f0fdcec..323f6d85a8 100644 --- a/pyiceberg/table/metadata.py +++ b/pyiceberg/table/metadata.py @@ -221,7 +221,9 @@ class TableMetadataCommonFields(IcebergBaseModel): current-snapshot-id even if the refs map is null.""" # validators - transform_properties_dict_value_to_str = field_validator('properties', mode='before')(transform_dict_value_to_str) + @field_validator('properties', mode='before') + def transform_properties_dict_value_to_str(cls, properties: Properties) -> Dict[str, str]: + return transform_dict_value_to_str(properties) def snapshot_by_id(self, snapshot_id: int) -> Optional[Snapshot]: """Get the snapshot by snapshot_id."""