Fokko commented on code in PR #5124:
URL: https://github.com/apache/iceberg/pull/5124#discussion_r918041548
##########
python/pyiceberg/transforms.py:
##########
@@ -64,6 +70,31 @@ class Transform(IcebergBaseModel, ABC, Generic[S, T]):
__root__: str = Field()
+ @classmethod
+ def __get_validators__(cls):
+ # one or more validators may be yielded which will be called in the
+ # order to validate the input, each validator will receive as an input
+ # the value returned from the previous validator
+ yield cls.validate
+
+ @classmethod
+ def validate(cls, v: Any):
+ # When Pydantic is unable to determine the subtype
+ # In this case we'll help pydantic a bit by parsing the transform type
ourselves
+ if isinstance(v, str):
+ if v == "identity":
+ bind_func = identity
+ elif v == "void":
+ bind_func = always_null # type: ignore
+ elif v.startswith("bucket"):
+ bind_func = functools.partial(bucket,
num_buckets=BaseBucketTransform.parse(v))
Review Comment:
Good point. I was in doubt when writing this if I should create a separate
parser for `prefix[int]` patterns, and I just did this. This removes the
`.parse` methods which are very similar anyway. Also refactored `fixed[int]` to
use the new parser.
--
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]