rdblue commented on code in PR #5124:
URL: https://github.com/apache/iceberg/pull/5124#discussion_r917461006
##########
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:
In types.py, `parse` is used to return an instance of the type, not to parse
part of the string form:
```python
FixedType.parse("fixed[16]") // -> FixedType(length=16)
```
If possible, I'd keep the expectations for those methods the same and return
a `BucketTransform` from `BucketTransform.parse`.
--
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]