Fokko commented on code in PR #4410:
URL: https://github.com/apache/iceberg-python/pull/4410#discussion_r4620499611


##########
pyiceberg/table/update/schema.py:
##########
@@ -74,6 +92,34 @@ class _Move:
     other_field_id: int | None = None
 
 
+def _is_valid_promotion(from_type: IcebergType, to_type: IcebergType) -> bool:
+    """Check a column type change against the spec's valid primitive type 
promotions.
+
+    Do not use promote() here: it is the read-side rule and also accepts 
string <-> binary and fixed(16) -> uuid.
+    """
+    if from_type == to_type:
+        return True
+    if isinstance(from_type, UnknownType):
+        # Unknown can be promoted to any primitive type in v3+
+        return isinstance(to_type, PrimitiveType)
+    if isinstance(from_type, IntegerType):
+        return isinstance(to_type, LongType)
+    if isinstance(from_type, FloatType):
+        return isinstance(to_type, DoubleType)
+    if isinstance(from_type, DecimalType) and isinstance(to_type, DecimalType):
+        return from_type.scale == to_type.scale and from_type.precision <= 
to_type.precision
+    return False
+
+
+def _is_deprecated_promotion(from_type: IcebergType, to_type: IcebergType) -> 
bool:
+    """Check for a non-spec type change that update_column still applies, with 
a deprecation warning."""
+    if isinstance(from_type, StringType) and isinstance(to_type, BinaryType):
+        return True
+    if isinstance(from_type, BinaryType) and isinstance(to_type, StringType):
+        return True

Review Comment:
   This was an earlier discussion: https://github.com/apache/iceberg/pull/5151
   
   I would just allow this for now. We should have one single place to do this, 
for example, `promote()` as suggested above.
   
   Same for the UUID. I believe we support this because of older versions of 
PyArrow, that didn't support UUIDs yet. This makes it a bit more lenient to 
still convert it into a UUID.
   
   Let's encode these edge cases as comments, so the LLM doesn't trip over it 
again.



##########
pyiceberg/table/update/schema.py:
##########
@@ -74,6 +92,34 @@ class _Move:
     other_field_id: int | None = None
 
 
+def _is_valid_promotion(from_type: IcebergType, to_type: IcebergType) -> bool:
+    """Check a column type change against the spec's valid primitive type 
promotions.
+
+    Do not use promote() here: it is the read-side rule and also accepts 
string <-> binary and fixed(16) -> uuid.
+    """
+    if from_type == to_type:
+        return True
+    if isinstance(from_type, UnknownType):
+        # Unknown can be promoted to any primitive type in v3+
+        return isinstance(to_type, PrimitiveType)
+    if isinstance(from_type, IntegerType):
+        return isinstance(to_type, LongType)
+    if isinstance(from_type, FloatType):
+        return isinstance(to_type, DoubleType)
+    if isinstance(from_type, DecimalType) and isinstance(to_type, DecimalType):
+        return from_type.scale == to_type.scale and from_type.precision <= 
to_type.precision
+    return False
+
+
+def _is_deprecated_promotion(from_type: IcebergType, to_type: IcebergType) -> 
bool:
+    """Check for a non-spec type change that update_column still applies, with 
a deprecation warning."""
+    if isinstance(from_type, StringType) and isinstance(to_type, BinaryType):
+        return True
+    if isinstance(from_type, BinaryType) and isinstance(to_type, StringType):
+        return True

Review Comment:
   This was an earlier discussion: https://github.com/apache/iceberg/pull/5151
   
   I would just allow this for now. We should have one single place to do this, 
for example, `promote()` as suggested above.
   
   Same for the UUID. I believe we support this because of older versions of 
PyArrow, that didn't support UUIDs yet. This makes it a bit more lenient to 
still convert it into a UUID.
   
   Let's encode these edge cases as comments in the code, so the LLM doesn't 
trip over it again.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to