Skip to content

Commit

Permalink
Add clarifying docs to transform result types (#1211)
Browse files Browse the repository at this point in the history
* add clarifying docs to transform result types

* add more context to docs

* re-add fixed first line

* fix lint
  • Loading branch information
kevinzwang authored Oct 9, 2024
1 parent 857abd0 commit 7cf0c22
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pyiceberg/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ def can_transform(self, source: IcebergType) -> bool:
return False

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

@abstractmethod
def project(self, name: str, pred: BoundPredicate[L]) -> Optional[UnboundPredicate[Any]]: ...
Expand Down Expand Up @@ -491,7 +499,7 @@ class DayTransform(TimeTransform[S]):
"""Transforms a datetime value into a day value.
Example:
>>> transform = MonthTransform()
>>> transform = DayTransform()
>>> transform.transform(DateType())(17501)
17501
"""
Expand All @@ -518,6 +526,11 @@ def can_transform(self, source: IcebergType) -> bool:
return isinstance(source, (DateType, TimestampType, TimestamptzType))

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

@property
Expand Down

0 comments on commit 7cf0c22

Please sign in to comment.