rdblue commented on code in PR #4908:
URL: https://github.com/apache/iceberg/pull/4908#discussion_r885097696
##########
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:
+ if isinstance(self._type, DateType):
+ return datetime.to_human_day(value)
+ elif isinstance(self._type, TimeType):
+ return datetime.to_human_time(value)
+ elif isinstance(self._type, TimestampType):
+ return datetime.to_human_timestamp(value)
+ elif isinstance(self._type, TimestamptzType):
+ return datetime.to_human_timestamptz(value)
+ else:
+ return str(value)
+
+ @_human_string.register(bytes)
+ def _(self, value: bytes) -> str:
+ if type(self._type) in {FixedType, BinaryType}:
Review Comment:
There is no need for an `if` here. The only way to handle binary is to
base64 encode it. It doesn't depend on the type.
--
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]