Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions pyiceberg/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,9 @@ def truncate_func(v: Any) -> Any:
def satisfies_order_of(self, other: Transform[S, T]) -> bool:
if self == other:
return True
elif (
isinstance(self.source_type, StringType)
and isinstance(other, TruncateTransform)
and isinstance(other.source_type, StringType)
):
elif isinstance(other, TruncateTransform):
# Matches the Java implementation: a truncation satisfies the order of any truncation with a
# width less than or equal to its own.
return self.width >= other.width

return False
Expand Down
18 changes: 18 additions & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,24 @@ def test_truncate_method(type_var: PrimitiveType, value: Any, expected_human_str
assert truncate_transform.satisfies_order_of(truncate_transform)


# Ported from TestSortOrder#testSatisfiesTruncateFieldOrder in the Java reference implementation:
# https://github.com/apache/iceberg/blob/main/core/src/test/java/org/apache/iceberg/TestSortOrder.java
@pytest.mark.parametrize(
"transform,other,expected",
[
(IdentityTransform(), TruncateTransform(2), True),
(TruncateTransform(2), IdentityTransform(), False),
(TruncateTransform(4), IdentityTransform(), False),
(TruncateTransform(4), TruncateTransform(2), True),
(TruncateTransform(2), TruncateTransform(4), False),
(TruncateTransform(2), TruncateTransform(2), True),
(TruncateTransform(3), BucketTransform(3), False),
],
)
def test_truncate_satisfies_order_of(transform: Transform[Any, Any], other: Transform[Any, Any], expected: bool) -> None:
assert transform.satisfies_order_of(other) is expected


def test_unknown_transform() -> None:
unknown_transform = UnknownTransform("unknown") # type: ignore
assert str(unknown_transform) == str(eval(repr(unknown_transform)))
Expand Down
Loading