rahulsmahadev commented on code in PR #4359:
URL: https://github.com/apache/iceberg-python/pull/4359#discussion_r4733853972
##########
pyiceberg/io/pyarrow.py:
##########
@@ -2760,6 +2760,25 @@ def _nan_value_counts_from_arrow(table: pa.Table,
stats_columns: dict[int, Stati
return nan_value_counts
+def _file_parquet_path_to_id_mapping(parquet_metadata: pq.FileMetaData,
file_schema: Schema) -> dict[str, int]:
+ """
+ Compute the mapping of the parquet column paths of a file to the Iceberg
IDs of its columns.
+
+ Unlike `parquet_path_to_id_mapping`, the paths are the ones stored in the
file, so a list element keeps
+ the name that the file gives it. The IDs come from the schema of the file,
so a column keeps its ID
+ when the table has renamed it.
+
+ Args:
+ parquet_metadata (pyarrow.parquet.FileMetaData): The metadata of the
parquet file.
+ file_schema (pyiceberg.schema.Schema): The Iceberg schema of the file,
as returned by
+ `_check_pyarrow_schema_compatible`.
+ """
+ # The leaf fields of the file schema are in the same depth-first order as
the parquet columns.
+ field_ids = [pair.field_id for pair in pre_order_visit(file_schema,
ID2ParquetPathVisitor())]
+ paths = [parquet_metadata.schema.column(pos).path for pos in
range(parquet_metadata.num_columns)]
+ return dict(zip(paths, field_ids, strict=True))
Review Comment:
Added the note in 95f3d42e. On the pre-rename question: I left it out of
scope, and the behaviour matches main. Checked on this branch and on main: a
file with a pre-rename column and no IDs fails add_files with "PyArrow table
contains more columns: a". After a drop and name reuse, the file maps to the
new column by name, and the stats and the scan agree. This PR does not change
that.
--
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]