Skip to content

Commit 7cf0c22

Browse files
authored
Add clarifying docs to transform result types (#1211)
* add clarifying docs to transform result types * add more context to docs * re-add fixed first line * fix lint
1 parent 857abd0 commit 7cf0c22

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pyiceberg/transforms.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ def can_transform(self, source: IcebergType) -> bool:
146146
return False
147147

148148
@abstractmethod
149-
def result_type(self, source: IcebergType) -> IcebergType: ...
149+
def result_type(self, source: IcebergType) -> IcebergType:
150+
"""Return the `IcebergType` produced by this transform given a source type.
151+
152+
This method defines both the physical and display representation of the partition field.
153+
154+
The physical representation must conform to the Iceberg spec. The display representation
155+
can deviate from the spec, such as by transforming the value into a more human-readable format.
156+
"""
157+
...
150158

151159
@abstractmethod
152160
def project(self, name: str, pred: BoundPredicate[L]) -> Optional[UnboundPredicate[Any]]: ...
@@ -491,7 +499,7 @@ class DayTransform(TimeTransform[S]):
491499
"""Transforms a datetime value into a day value.
492500
493501
Example:
494-
>>> transform = MonthTransform()
502+
>>> transform = DayTransform()
495503
>>> transform.transform(DateType())(17501)
496504
17501
497505
"""
@@ -518,6 +526,11 @@ def can_transform(self, source: IcebergType) -> bool:
518526
return isinstance(source, (DateType, TimestampType, TimestamptzType))
519527

520528
def result_type(self, source: IcebergType) -> IcebergType:
529+
"""Return the result type of a day transform.
530+
531+
The physical representation conforms to the Iceberg spec as DateType is internally converted to int.
532+
The DateType returned here provides a more human-readable way to display the partition field.
533+
"""
521534
return DateType()
522535

523536
@property

0 commit comments

Comments
 (0)