Skip to content

Commit da66533

Browse files
authored
Reject unsupported identity transform types (#3517)
<!-- Thanks for opening a pull request! --> # Rationale for this change Per spec[1], the identity transform source type must be any primitive except for geometry, geography, and variant. This PR rejects GeographyType and GeometryType as source types for identity transforms.(No VariantType yet) [1] https://iceberg.apache.org/spec/#partition-transforms ## Are these changes tested? Yes ## Are there any user-facing changes? No
1 parent d871cd2 commit da66533

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pyiceberg/transforms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
DateType,
7474
DecimalType,
7575
FixedType,
76+
GeographyType,
77+
GeometryType,
7678
IcebergType,
7779
IntegerType,
7880
LongType,
@@ -717,7 +719,8 @@ def transform(self, source: IcebergType) -> Callable[[S | None], S | None]:
717719
return lambda v: v
718720

719721
def can_transform(self, source: IcebergType) -> bool:
720-
return source.is_primitive
722+
# TODO: disallow VariantType when PyIceberg supports it.
723+
return source.is_primitive and not isinstance(source, (GeographyType, GeometryType))
721724

722725
def result_type(self, source: IcebergType) -> IcebergType:
723726
return source

tests/test_transforms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
DoubleType,
102102
FixedType,
103103
FloatType,
104+
GeographyType,
105+
GeometryType,
104106
IntegerType,
105107
LongType,
106108
NestedField,
@@ -255,6 +257,11 @@ def test_identity_transform_unknown_type() -> None:
255257
assert IdentityTransform().to_human_string(UnknownType(), None) == "null"
256258

257259

260+
@pytest.mark.parametrize("type_var", [GeometryType(), GeographyType()])
261+
def test_identity_can_transform_unsupported_type(type_var: PrimitiveType) -> None:
262+
assert not IdentityTransform().can_transform(type_var)
263+
264+
258265
def test_string_with_surrogate_pair() -> None:
259266
string_with_surrogate_pair = "string with a surrogate pair: 💰"
260267
as_bytes = bytes(string_with_surrogate_pair, UTF8)

0 commit comments

Comments
 (0)