geruh commented on code in PR #2410:
URL: https://github.com/apache/iceberg-python/pull/2410#discussion_r2609723525


##########
pyiceberg/partitioning.py:
##########
@@ -249,6 +250,36 @@ def partition_to_path(self, data: Record, schema: Schema) 
-> str:
         path = "/".join([field_str + "=" + value_str for field_str, value_str 
in zip(field_strs, value_strs, strict=True)])
         return path
 
+    def check_compatible(self, schema: Schema, allow_missing_fields: bool = 
False) -> None:
+        # if the underlying field is dropped, we cannot check they are 
compatible -- continue
+        schema_fields = schema._lazy_id_to_field
+        parents = _index_parents(schema)
+
+        def validate_parents_are_structs(field_id: int) -> None:
+            parent_id = parents.get(field_id)
+            while parent_id:
+                parent_type = schema.find_type(parent_id)
+                if not parent_type.is_struct:
+                    raise ValidationError("Invalid partition field parent: 
%s", parent_type)
+                parent_id = parents.get(parent_id)
+
+        for field in self.fields:
+            source_field = schema_fields.get(field.source_id)
+            if allow_missing_fields and source_field:

Review Comment:
   Should this be: 
   
   ```
   if allow_missing_fields and source_field is None:
       continue
   ```
   
   
https://github.com/apache/iceberg/blob/23dc32e5f1130c9d79d71cbf0be5b85162d8976c/api/src/main/java/org/apache/iceberg/PartitionSpec.java#L648-L650



##########
pyiceberg/partitioning.py:
##########
@@ -249,6 +250,36 @@ def partition_to_path(self, data: Record, schema: Schema) 
-> str:
         path = "/".join([field_str + "=" + value_str for field_str, value_str 
in zip(field_strs, value_strs, strict=True)])
         return path
 
+    def check_compatible(self, schema: Schema, allow_missing_fields: bool = 
False) -> None:
+        # if the underlying field is dropped, we cannot check they are 
compatible -- continue
+        schema_fields = schema._lazy_id_to_field
+        parents = _index_parents(schema)
+
+        def validate_parents_are_structs(field_id: int) -> None:
+            parent_id = parents.get(field_id)
+            while parent_id:
+                parent_type = schema.find_type(parent_id)
+                if not parent_type.is_struct:
+                    raise ValidationError("Invalid partition field parent: 
%s", parent_type)

Review Comment:
   nit: should we also use f string here to align with others



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