Repository navigation
Reject columns whose field IDs are not in the table schema on write - #4455
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
Appending, overwriting or upserting an Arrow table whose fields carry field IDs dropped the columns whose ID is not in the table schema, such as an extra column or one that was dropped and added back, while the same input without field IDs is rejected. The write paths now pass reject_unknown_field_ids to _check_pyarrow_schema_compatible, which raises a ValueError that names each such column and its field ID. add_files is unchanged. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
@kevinjqliu, you reviewed #2662 (field IDs in add_files) and @jeroko wrote it. Could you take a look when you have a chance? Thanks! |
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
Bug: when every field of an Arrow table carries a field ID,
appenddrops the columns whose field ID is not in the table schema, without an error:The same happens to a column that was dropped and added back: an Arrow schema taken before
delete_column("x")andadd_column("x", LongType())hasxwith field ID 2, the newxhas field ID 3, and the appended values are stored as null.overwriteanddynamic_partition_overwritelose these columns too, andupsertcan lose them on inserts or when updating with a stale ID. Without field IDs, the extrazis already rejected (PyArrow table contains more columns: z). Fokko raised the same concern on #4419 (review): silently dropping a column on append loses data without any signal.Fix: the four write paths now reject input field IDs that are not in the table schema, before anything is written:
add_filesis unchanged (#4359). Note that #4444 currently tests thatupsertaccepts such a stale ID; with this change it raises.Java: Spark's write builder gives the input the table's field IDs by name (
SparkSchemaUtil.convert->TypeUtil.reassignIds) and fails on unknown columns (Field z not found in source schema) unless merge-schema adds them first. PyIceberg has no merge-schema option on write and keeps the input's own IDs when every field has one, so it rejects the stalexinstead of writing it to the newx.Are these changes tested?
Yes,
test_write_rejects_field_ids_not_in_table_schemaintests/catalog/test_catalog_behaviors.pyruns both cases through the four write APIs on an evolved table, checks that nothing is committed, and that appends with a renamed column's old name, reordered, promoted, missing optional and ID-less columns still work. It fails on main withDID NOT RAISE ValueErrorand passes with this change.test_schema_mismatch_unknown_field_idsintests/io/test_pyarrow.pycovers struct fields, list elements and map values.Are there any user-facing changes?
Yes, writes now reject unknown field IDs, including dropped columns kept in Arrow data read from older Parquet files.
Please add the
changeloglabel.This pull request and its description were written by Isaac.