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


##########
pyiceberg/io/pyarrow.py:
##########
@@ -1228,11 +1252,21 @@ def primitive(self, primitive: pa.DataType) -> T:
 
 
 def _get_field_id(field: pa.Field) -> Optional[int]:
-    return (
-        int(field_id_str.decode())
-        if (field.metadata and (field_id_str := 
field.metadata.get(PYARROW_PARQUET_FIELD_ID_KEY)))
-        else None
-    )
+    """Return the Iceberg field ID from Parquet or ORC metadata if 
available."""
+    if not field.metadata:
+        return None
+
+    # Try Parquet field ID first
+    field_id_bytes = field.metadata.get(PYARROW_PARQUET_FIELD_ID_KEY)
+    if field_id_bytes:
+        return int(field_id_bytes.decode())
+
+    # Fallback: try ORC field ID
+    field_id_bytes = field.metadata.get(ORC_FIELD_ID_KEY)
+    if field_id_bytes:
+        return int(field_id_bytes.decode())

Review Comment:
   Style nit, a bit more concise:
   ```suggestion
       if field.metadata:
           # Try Parquet field ID first
           if field_id_bytes := 
field.metadata.get(PYARROW_PARQUET_FIELD_ID_KEY):
               return int(field_id_bytes.decode())
   
           # Fallback: try ORC field ID
           if field_id_bytes := field.metadata.get(ORC_FIELD_ID_KEY):
               return int(field_id_bytes.decode())
   ```



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