Repository navigation
Core: Keep mapped names of existing fields when a column is added - #4332
Open
Anurag-S1ngh wants to merge 1 commit into
Open
Anurag-S1ngh wants to merge 1 commit into
Anurag-S1ngh wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
update_schema()updates the default name mapping, and_UpdateMappingremoved a mapped name from an existing field whenever a new or renamed field claimed that name. For files without field ids those names are the only way a column is found, so the removal changed what an existing column reads.After renaming
atob, the mapping for field 1 holds both names. Adding a new columnathen strippedafrom field 1 and gave it to the new field. Files added withadd_fileswere read through the name mapping, sobstarted reading null and the newareceived the old values. Dropping and re-adding a column had the same effect.Existing names now stay on the field they were mapped to, and newly added fields are appended to the mapping. A name that a file was written with keeps resolving to the field id it was written for, which matches the behavior of files that carry field ids. Dropped fields keep their entry in the mapping for the same reason: their names must not start resolving to a later column with the same name.
Are these changes tested?
Yes.
tests/catalog/test_catalog_behaviors.py::test_add_column_keeps_values_of_renamed_column_without_field_idsadds a Parquet file without field ids, renames the column, adds a column with the old name, and asserts the renamed column still reads its values while the new one reads null. It runs against the memory, sql, and sql_without_rowcount catalogs and fails on main.tests/table/test_name_mapping.py::test_update_mapping_keeps_name_of_existing_fieldcovers the mapping directly, and the existingtest_update_mappingnow expects the old field to keep its name.Full unit suite:
4564 passed, 5 skipped.prek run -apasses.Are there any user-facing changes?
Yes. Adding a column no longer changes the values read from files without field ids, and a reused column name no longer re-attributes their data to the new column.
Closes #4318