Repository navigation
fix(inspect): map partition record by field id to support renamed partition fields - #4363
Conversation
…tition fields When a partition field is renamed (via update_spec().rename_field() or via v1 auto-renaming voided fields on re-add), specs_struct() adopts the latest field names per field_id. Previously, inspect.py constructed partition dicts using the historical spec's field names directly, causing PyArrow conversion to silently drop pre-rename partition values as None (or misattribute them to newly added fields sharing the old name). This updates InspectTable.entries(), partitions(), and _get_files_from_manifest() to map partition field values by field_id using specs_struct() names, and keys partitions_map by (spec_id, partition_record_dict) to track partition stats per specification layout.
d8cf7b2 to
50939d9
Compare
Fokko
left a comment
There was a problem hiding this comment.
Thanks @Ankitkj1999, this is a clean fix and the added tests cover both the rename and the v1 void/re-add cases really well.
Left a couple of small points:
- In
partitions()and_get_files_from_manifest(),id_to_name.get(field.field_id, field.name)falls back to the per-spec name when the field id is missing fromspecs_struct(). When can that actually happen given every spec here comes from the samepartition_specsmap? If it is unreachable, a direct[...]lookup with a comment might be clearer; if it is reachable (e.g. voided fields sharing a name), maybe worth a test asserting the historical name wins. - The
partitions_mapkey change fromstrtotuple[int, Any]is internal, but it does change the shape of_partitions_mapused bypartitions(). I checked the existing test attests/table/test_inspect.py:93still lines up, all good on my side.
CI is green including the integration jobs, LGTM!
|
Thanks for the review @Fokko! You're completely right — since \specs_struct()\ guarantees that all partition field IDs across the relevant specs are collected and mapped to their latest names, a missing field ID is indeed unreachable in valid tables. I've updated the lookups to direct \id_to_name[field.field_id]\ indexing across \entries(), \partitions(), and _get_files_from_manifest(), with an explanatory comment noting that \specs_struct()\ guarantees presence. |
Fokko
left a comment
There was a problem hiding this comment.
Thanks @Ankitkj1999 for the fix and for addressing the review so quickly!
Closes #4362
Rationale for this change
When a partition field is renamed (via
update_spec().rename_field()or via v1 auto-renaming voided fields on re-add),specs_struct()adopts the latest field name perfield_id. Previously,inspect.pyconstructed partition dictionaries using each entry's historical spec field names directly (field.name), causing PyArrow conversion to silently drop pre-rename partition values asNone(or misattribute them to newly added fields sharing the old name).This PR:
InspectTable.entries(),partitions(), and_get_files_from_manifest()to map partition values byfield.field_idthroughspecs_struct(), preserving historical partition values in the PyArrow output.partitions_mapinpartitions()by(file.spec_id, partition_record_dict)so partition counts and statistics are tracked per specification layout.Are these changes tested?
Yes:
test_inspect_partitions_and_files_after_rename_fieldintests/table/test_inspect.pytestingpartitions(),files(),data_files(),all_files(),all_data_files(), andentries().test_inspect_files_after_v1_partition_field_readdintests/table/test_inspect.pytesting field attribution across voided and re-added partition fields in format v1 tables.Are there any user-facing changes?
Bugfix:
table.inspecttables accurately report historical partition values after partition field renames and partition re-additions.