Repository navigation
Reject columns whose field IDs are not in the table schema on write - #4455
rahulsmahadev wants to merge 2 commits 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 <[email protected]>
|
@kevinjqliu, you reviewed #2662 (field IDs in add_files) and @jeroko wrote it. Could you take a look when you have a chance? Thanks! |
|
I'm unsure if this check needs to happen on PyIceberg. The user is reponsible in the end for the Table schema, and the data it provides. Curious to learn what others think |
|
Thanks for taking a look! Without field IDs we already raise for the extra column ( |
Main moved the append and overwrite schema checks into _prepare_arrow_input, so the helper now passes reject_unknown_field_ids=True, as the inline checks did. Co-authored-by: Isaac <[email protected]>
|
@Fokko could you take a look when you have a chance? Thanks! |
|
Closing this for now, since the extra check changes what writes accept and we haven't agreed PyIceberg should enforce it. |
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.