Fokko commented on code in PR #4717: URL: https://github.com/apache/iceberg/pull/4717#discussion_r882821386
########## python/src/iceberg/table/partitioning.py: ########## @@ -14,8 +14,13 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +from typing import Dict, Iterable, List, Tuple + +from iceberg.schema import Schema from iceberg.transforms import Transform +_PARTITION_DATA_ID_START: int = 1000 + class PartitionField: Review Comment: We can also go full pythonic and bump the dataclass to a pydantic model. With Pydantic you can annotate the fields with validators: https://pydantic-docs.helpmanual.io/usage/validators/ We could use the generate Open API classes as the base classes and extend from those: https://github.com/apache/iceberg/pull/4858/files#diff-4f32e455c8da9fc5dc641048dc398741b72e928f359bfb9e5ef3640e7d32873e This also allows us to add validation. For example, the `BaseUserModel` is the generated one from open-api, and the `UserModel` is the one extended with all the (convience) methods attached to it: ```python from pydantic import BaseModel, ValidationError, validator class BaseUserModel(BaseModel): name: str username: str password1: str password2: str class UserModel(BaseUserModel): @validator('name') def name_must_contain_space(cls, v): if ' ' not in v: raise ValueError('must contain a space') return v.title() @validator('password2') def passwords_match(cls, v, values, **kwargs): if 'password1' in values and v != values['password1']: raise ValueError('passwords do not match') return v @validator('username') def username_alphanumeric(cls, v): assert v.isalnum(), 'must be alphanumeric' return v user = UserModel( name='samuel colvin', username='scolvin', password1='zxcvbn', password2='zxcvbn', ) print(user) #> name='Samuel Colvin' username='scolvin' password1='zxcvbn' password2='zxcvbn' try: UserModel( name='samuel', username='scolvin', password1='zxcvbn', password2='zxcvbn2', ) except ValidationError as e: print(e) """ 2 validation errors for UserModel name must contain a space (type=value_error) password2 passwords do not match (type=value_error) """ ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
