Repository navigation
Map add_files columns without field IDs by the table's name mapping - #4603
Open
rahulsmahadev wants to merge 5 commits into
Open
rahulsmahadev wants to merge 5 commits into
rahulsmahadev wants to merge 5 commits into
Conversation
add_files matched columns without field IDs against a mapping built from the table's current names, so a file that still used a renamed column's old name was rejected, although the table's name mapping keeps that name and the scan reads the file through it. add_files now uses the table's name mapping; writes keep matching the current names. Co-authored-by: Isaac <no-reply@databricks.com>
With the table's name mapping, a file with both the old and the new name of a renamed column resolved both to one field ID: the scan read one of them and the value counts added up. add_files now rejects such files, and files with a field ID twice, as Java's import does, and documents its ValueError. Co-authored-by: Isaac <no-reply@databricks.com>
The duplicate check must not take the short names of a list of structs for a second column, and a file with a current column that the stored name mapping lacks must be rejected without changing the table. Co-authored-by: Isaac <no-reply@databricks.com>
Fokko
approved these changes
Dec 3, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Verified the rename and list-of-struct cases pass, and the mapping parity with Spark add_files checks out. The windows CI failure is the flaky content cache test, unrelated here. Thanks @rahulsmahadev 🚀
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
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
Follow-up to #4359, for files without field IDs: this fixes the first case in this #4359 review comment. The second case there, a dropped column whose name a new column reuses, does not change: the mapping update moves the name to the new column (#4318), and
add_filesand the scan both follow the mapping.Bug:
add_filesresolves the columns of a file without field IDs with a name mapping built from the table's current names. A rename keeps the old name in the table's name mapping (schema.name-mapping.default), and the scan reads such files through that mapping, butadd_filesrejects a file that still uses the old name:The spec maps several names to one field ID "to support cases where a field may have different names in different data files". A renamed nested field fails the same way.
Fix:
parquet_file_to_data_filepasses the table's name mapping to_check_pyarrow_schema_compatible, so the check and the statistics resolve the columns the way the scan does. Without a stored mapping the current names are used as before, and writes are unchanged. A file could now resolve two columns, the old and the new name, to one field ID, soadd_filesrejects files with two columns for one field ID (Multiple file columns resolve to field ID 2: full_name, name). This also rejects a file with the same field ID twice, which main added; the scan then read one of the two columns and the value counts added up.Java: Spark's
add_filesprocedure creates the name mapping if there is none, andSparkTableUtilpasses it throughTableMigrationUtil.listPartitiontoParquetUtil.fileMetrics, which applies it to files without field IDs;SchemaUpdatekeeps old names in it (MappingUtil.update). Java's importer also fails on duplicate field IDs, but does not check the file against the table schema.add_fileskeeps that check, so a column that maps to no current field, such as the old name of a dropped column, is still rejected.Are these changes tested?
Yes, in
tests/io/test_pyarrow.py:test_add_files_matches_columns_by_table_name_mapping(top-level and list-of-struct renames, rows and value counts, files with two columns for one field ID, a dropped column's old name, and an incomplete stored mapping) andtest_schema_compatible_with_name_mapping(the new parameter and its default). Both fail on main (the first withValueError: PyArrow table contains more columns: address.element.zip, address.zip, name, the second with aTypeErrorfor the new parameter) and pass with this change.Are there any user-facing changes?
Yes.
add_filesaccepts old column names recorded in the table's mapping and rejects duplicate resolved field IDs. It also rejects files without field IDs when their current table columns are missing from the stored mapping; main added those files, then failed to scan them.Please add the
changeloglabel.This pull request and its description were written by Isaac.