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


##########
pyiceberg/io/pyarrow.py:
##########
@@ -1216,6 +1216,25 @@ def _field_id(self, field: pa.Field) -> int:
         return -1
 
 
+def _get_column_projection_values(
+    file: DataFile,
+    projected_schema: Schema,
+    projected_field_ids: Set[int],
+    file_project_schema: Schema,
+    partition_spec: Optional[PartitionSpec] = None,
+) -> Dict[str, object]:
+    """Apply Column Projection rules to File Schema."""
+    projected_missing_fields = {}
+
+    for field_id in 
projected_field_ids.difference(file_project_schema.field_ids):
+        if partition_spec is not None:
+            for partition_field in 
partition_spec.fields_by_source_id(field_id):
+                if isinstance(partition_field.transform, IdentityTransform) 
and partition_field.name in file.partition.__dict__:
+                    projected_missing_fields[partition_field.name] = 
file.partition.__dict__[partition_field.name]

Review Comment:
   @gabeiglio I was out indeed, sorry for the late reply. It should look like 
this:
   
   ```python
   def _get_column_projection_values(
       file: DataFile,
       projected_schema: Schema,
       projected_field_ids: Set[int],
       file_project_schema: Schema,
       partition_spec: PartitionSpec,
   ) -> Dict[str, object]:
       """Apply Column Projection rules to File Schema."""
       projected_missing_fields = {}
   
       partition_schema = partition_spec.partition_type(projected_schema)
       accessors = build_position_accessors(partition_schema)
   
       for field_id in 
projected_field_ids.difference(file_project_schema.field_ids):
           if partition_spec is not None:
               for partition_field in 
partition_spec.fields_by_source_id(field_id):
                   projected_missing_fields[partition_field.name] = 
accessors.get(partition_field.field_id).get(file.partition)
   
       return projected_missing_fields
   ```
   
   I've tested this locally, and it works like a charm with the test you 
provided.
   
   > One question I have its that if the file.partition metadata is written in 
order then it is guaranteed that the first record in the tuple would be the 
first partition column from the partition spec?
   
   The order should match, but I'm more afraid that the names might be messed 
up by some half-baked implementation since they are not part of the Iceberg 
specification. The how to handle field-IDs is defined by the spec, and 
therefore should be the way to look up the fields.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to