diff --git a/pyiceberg/transforms.py b/pyiceberg/transforms.py index 74925c695f..45c8ffd196 100644 --- a/pyiceberg/transforms.py +++ b/pyiceberg/transforms.py @@ -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 diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 998d8a224d..2f9fab0951 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -513,6 +513,14 @@ def test_truncate_method(type_var: PrimitiveType, value: Any, expected_human_str assert truncate_transform.satisfies_order_of(truncate_transform) +def test_truncate_satisfies_order_of_different_widths() -> None: + assert TruncateTransform(3).satisfies_order_of(TruncateTransform(3)) + assert TruncateTransform(5).satisfies_order_of(TruncateTransform(3)) + assert not TruncateTransform(3).satisfies_order_of(TruncateTransform(5)) + assert not TruncateTransform(3).satisfies_order_of(IdentityTransform()) + assert not TruncateTransform(3).satisfies_order_of(BucketTransform(3)) + + def test_unknown_transform() -> None: unknown_transform = UnknownTransform("unknown") # type: ignore assert str(unknown_transform) == str(eval(repr(unknown_transform)))