rahulsmahadev commented on code in PR #4410:
URL: https://github.com/apache/iceberg-python/pull/4410#discussion_r4630497674
##########
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:
Review Comment:
Yes, done in b130b6a4. `update_column()` uses `promote()` again, and
`_is_valid_promotion` is gone.
##########
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:
Makes sense, thanks for the pointer to apache/iceberg#5151. I dropped the
deprecation so these stay allowed, and added comments in `promote()` for string
<-> binary and fixed(16) -> uuid, plus one in `update_column()` that points
there. I also updated the title and description since this is now comments and
a test only.
--
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]