Skip to content

Commit

Permalink
properties validator
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjqliu committed Mar 9, 2024
1 parent 9fe9cff commit 428b894
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pyiceberg/catalog/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 3 additions & 1 deletion pyiceberg/table/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 428b894

Please sign in to comment.