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


##########
pyiceberg/partitioning.py:
##########
@@ -249,6 +249,31 @@ def partition_to_path(self, data: Record, schema: Schema) 
-> str:
 UNPARTITIONED_PARTITION_SPEC = PartitionSpec(spec_id=0)
 
 
+def validate_partition_name(
+    field_name: str,
+    partition_transform: Transform[Any, Any],
+    source_id: int,
+    schema: Schema,
+    partition_names: Set[str],
+) -> None:
+    """Validate that a partition field name doesn't conflict with schema field 
names."""
+    try:
+        schema_field = schema.find_field(field_name)
+    except ValueError:
+        return  # No conflict if field doesn't exist in schema
+
+    if isinstance(partition_transform, (IdentityTransform, VoidTransform)):
+        # For identity and void transforms, allow conflict only if sourced 
from the same schema field
+        if schema_field.field_id != source_id:
+            raise ValueError(f"Cannot create identity partition sourced from 
different field in schema: {field_name}")
+    else:
+        raise ValueError(f"Cannot create partition from name that exists in 
schema: {field_name}")
+    if not field_name:
+        raise ValueError("Undefined name")

Review Comment:
   I don't think this will ever hit, since `field_name` is not `Optional`



-- 
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