This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-4410-f3d147b7f4c4a2d0fe9d436c02bf14eae41fc9c5
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git

commit 5c3a2bc6a8659d8c575935f504ce87a7991eac50
Author: Rahul Shivu Mahadev <[email protected]>
AuthorDate: Wed Nov 25 23:16:05 2026 +0000

    Document why promote() allows string <-> binary and fixed(16) -> uuid 
(#4410)
    
    * Deprecate implicit non-spec type changes in update_column
    
    update_column applied string <-> binary and fixed(16) -> uuid silently,
    using the read-side promote(). Check the spec's promotion list instead.
    Those three pairs now warn with a DeprecationWarning, and are rejected
    in a later release unless allow_incompatible_changes=True is set.
    
    Co-authored-by: Isaac <[email protected]>
    
    * Retrigger CI
    
    Co-authored-by: Isaac <[email protected]>
    
    * Allow non-spec type changes in update_column and document them
    
    Drop the deprecation: update_column keeps using promote(), the one place
    for type promotions. Comment why promote() allows string <-> binary and
    fixed(16) -> uuid, and test that update_column allows them.
    
    Co-authored-by: Isaac <[email protected]>
    
    ---------
    
    Co-authored-by: Isaac <[email protected]>
---
 pyiceberg/schema.py              |  7 ++++++-
 pyiceberg/table/update/schema.py |  2 ++
 tests/test_schema.py             | 12 ++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/schema.py b/pyiceberg/schema.py
index aa4e7493d..d57095f58 100644
--- a/pyiceberg/schema.py
+++ b/pyiceberg/schema.py
@@ -1705,6 +1705,8 @@ def _(file_type: FloatType, read_type: IcebergType) -> 
IcebergType:
 @promote.register(StringType)
 def _(file_type: StringType, read_type: IcebergType) -> IcebergType:
     if isinstance(read_type, BinaryType):
+        # Not a valid promotion in the spec, but allowed on purpose: strings 
and binary are both stored as bytes, so one
+        # can be read as the other. See 
https://github.com/apache/iceberg/pull/5151. Schema updates use this rule too.
         return read_type
     else:
         raise ResolveError(f"Cannot promote an string to {read_type}")
@@ -1713,6 +1715,7 @@ def _(file_type: StringType, read_type: IcebergType) -> 
IcebergType:
 @promote.register(BinaryType)
 def _(file_type: BinaryType, read_type: IcebergType) -> IcebergType:
     if isinstance(read_type, StringType):
+        # Not a valid promotion in the spec, but allowed on purpose, see 
string -> binary above
         return read_type
     else:
         raise ResolveError(f"Cannot promote an binary to {read_type}")
@@ -1732,7 +1735,9 @@ def _(file_type: DecimalType, read_type: IcebergType) -> 
IcebergType:
 @promote.register(FixedType)
 def _(file_type: FixedType, read_type: IcebergType) -> IcebergType:
     if isinstance(read_type, UUIDType) and len(file_type) == 16:
-        # Since pyarrow reads parquet UUID as fixed 16-byte binary, the 
promotion is needed to ensure read compatibility
+        # Not a valid promotion in the spec, but allowed on purpose: older 
PyArrow versions had no UUID type and read
+        # Parquet UUIDs as fixed 16-byte binary. This keeps such columns 
readable as UUID, and lets update_column()
+        # turn them into UUID.
         return read_type
     else:
         raise ResolveError(f"Cannot promote {file_type} to {read_type}")
diff --git a/pyiceberg/table/update/schema.py b/pyiceberg/table/update/schema.py
index 6aa601c9d..4613a1f3d 100644
--- a/pyiceberg/table/update/schema.py
+++ b/pyiceberg/table/update/schema.py
@@ -473,6 +473,8 @@ class UpdateSchema(UpdateTableMetadata["UpdateSchema"]):
                 raise ValidationError(f"Cannot change column type: 
{field.field_type} is not a primitive")
 
             if not self._allow_incompatible_changes and field.field_type != 
field_type:
+                # promote() is the one place for the allowed type changes. It 
also allows string <-> binary and
+                # fixed(16) -> uuid, which are not in the spec, see the 
comments there.
                 try:
                     promote(field.field_type, field_type)
                 except ResolveError as e:
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 9f1628299..ed0982c40 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -1406,6 +1406,18 @@ def 
test_detect_invalid_promotion_string_to_float(table_v2: Table) -> None:
         _ = UpdateSchema(transaction=Transaction(table_v2), 
schema=current_schema).union_by_name(new_schema)._apply()
 
 
+def test_update_column_allows_non_spec_promotions(table_v2: Table) -> None:
+    # Not valid promotions in the spec, but allowed on purpose, see promote()
+    for current_type, new_type in [(StringType(), BinaryType()), 
(BinaryType(), StringType()), (FixedType(16), UUIDType())]:
+        current_schema = Schema(NestedField(field_id=1, name="aCol", 
field_type=current_type, required=False))
+        update = UpdateSchema(transaction=Transaction(table_v2), 
schema=current_schema).update_column("aCol", new_type)
+        assert update._apply().find_field("aCol").field_type == new_type
+
+    current_schema = Schema(NestedField(field_id=1, name="aCol", 
field_type=FixedType(15), required=False))
+    with pytest.raises(ValidationError, match=r"^Cannot change column type: 
aCol: fixed\[15\] -> uuid$"):
+        UpdateSchema(transaction=Transaction(table_v2), 
schema=current_schema).update_column("aCol", UUIDType())
+
+
 # decimal(P,S) Fixed-point decimal; precision P, scale S -> Scale is fixed [1],
 # precision must be 38 or less
 def test_type_promote_decimal_to_fixed_scale_with_wider_precision(table_v2: 
Table) -> None:

Reply via email to