Fokko commented on code in PR #5124:
URL: https://github.com/apache/iceberg/pull/5124#discussion_r918359810
##########
python/pyiceberg/transforms.py:
##########
@@ -64,11 +72,32 @@ class Transform(IcebergBaseModel, ABC, Generic[S, T]):
__root__: str = Field()
- def __call__(self, value: Optional[S]) -> Optional[T]:
- return self.apply(value)
+ @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:
+ return IdentityTransform()
+ elif v == VOID:
+ return VoidTransform()
+ elif v.startswith(BUCKET):
+ return BucketTransform(num_buckets=BUCKET_PARSER.match(v))
+ elif v.startswith(TRUNCATE):
+ return TruncateTransform(width=BUCKET_PARSER.match(v))
+ else:
+ return UnknownTransform(transform=v)
+ return v
@abstractmethod
- def apply(self, value: Optional[S]) -> Optional[T]:
+ def hash_function(self, source: IcebergType) -> Callable[[Optional[S]],
Optional[T]]:
Review Comment:
Good call, I've updated the code
--
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]