rdblue commented on code in PR #4908:
URL: https://github.com/apache/iceberg/pull/4908#discussion_r885101579
##########
python/src/iceberg/transforms.py:
##########
@@ -224,6 +226,67 @@ def hash(self, value: UUID) -> int:
)
+class IdentityTransform(Transform[S, S]):
+ """Transforms a value into itself.
+
+ Example:
+ >>> transform = IdentityTransform(StringType())
+ >>> transform.apply('hello-world')
+ 'hello-world'
+ """
+
+ def __init__(self, source_type: IcebergType):
+ super().__init__(
+ "identity",
+ f"transforms.identity(source_type={repr(source_type)})",
+ )
+ self._type = source_type
+
+ def apply(self, value: Optional[S]) -> Optional[S]:
+ return value
+
+ def can_transform(self, source: IcebergType) -> bool:
+ return source.is_primitive
+
+ def result_type(self, source: IcebergType) -> IcebergType:
+ return source
+
+ @property
+ def preserves_order(self) -> bool:
+ return True
+
+ def satisfies_order_of(self, other: Transform) -> bool:
+ """ordering by value is the same as long as the other preserves
order"""
+ return other.preserves_order
+
+ def to_human_string(self, value: Optional[S]) -> str:
+ return self._human_string(value)
+
+ @singledispatchmethod
+ def _human_string(self, value: Optional[S]) -> str:
+ return str(value) if value is not None else "null"
+
+ @_human_string.register(int)
+ def _(self, value: int) -> str:
Review Comment:
Rather than using `isinstance`, why not add another `@singledispatchmethod`:
`_int_to_human_string(valueType: IcebergType, value: int)`? That seems a bit
cleaner to me.
--
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]