Repository navigation
Find partition source columns the same way as the writer - #4457
Draft
rahulsmahadev wants to merge 2 commits into
Draft
rahulsmahadev wants to merge 2 commits into
rahulsmahadev wants to merge 2 commits into
Conversation
_determine_partitions read the partition source from the input by its full name in the table schema, split on dots, while the writer finds each column by following the table's struct path with the input's own names. A dotted struct name raised KeyError, and an input with field IDs from before a rename got its partition values from another column, so filtered scans missed rows. Follow the writer's path and names instead. Co-authored-by: Isaac <[email protected]>
Contributor
Author
Contributor
Author
|
@rambleraptor could you take a look when you have a chance? Thanks! |
Appending input without an optional column that a partition field uses failed in _determine_partitions, although the schema check allows a missing optional column and the writer stores nulls for it. Use those nulls as the source values, so the rows go to the null partition. Co-authored-by: Isaac <[email protected]>
rahulsmahadev
marked this pull request as draft
December 1, 2026 02:16
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:
_determine_partitionsreads the partition source from the input by its full name in the current table schema, split on dots, while the writer follows the table's struct path with the input's own names (task_schema, from the Arrow field IDs or the name mapping). That gives two bugs:a.band an identity partition on its childc,appendraisesKeyError: 'Field "a" does not exist in schema', because the split (from Fix support for writing to nested field partition #2204) looks for a columna.Fix: find the source the same way as the writer, following its struct path in the table schema with each name taken from the input schema, and pass the names to Arrow literally. How the writer matches columns is unchanged.
Bug: since #921 an input can leave out optional columns, which the writer stores as nulls, but
appendraises when a partition field uses such a column (ArrowInvalidfor a missing struct field):Fix: when an optional field on the source's path is missing from the input, partition on the nulls that the writer stores for it, so the rows go to the null partition. Schema validation is unchanged. This also fixes an input that has the column under another field ID, where main took the partition from values the writer does not store.
Java:
SparkWriteBuilderaligns the input schema's IDs with the table, andSparkWritereuses aPartitionKeywhoseStructTransformreads each row throughschema.accessorForField(sourceId)of that input schema. ThatStructTransformraisesCannot build accessor for fieldwhen the source is missing from the input schema; PyIceberg accepts such input since #921, so the partition follows the nulls its writer stores.Not covered here: dynamic partition overwrite still has #4196 (open fix #4204), and the row filter converter (
_ConvertToArrowExpression._get_field_name) also splits names, so delete rewrites and filtered scans ofadd_filesfiles with dotted struct names can still raiseArrowInvalid.Are these changes tested?
Yes,
test_append_to_identity_partitioned_table_with_dotted_names,test_append_with_field_ids_after_swapping_column_namesandtest_partition_values_follow_writer_struct_path(a guard for unchanged behavior) intests/catalog/test_catalog_behaviors.py, andtest_partition_for_nested_field_with_dotted_namesintests/io/test_pyarrow.py. On main the dotted-name tests fail with theKeyErrorabove and the swap test with partitionyinstead ofx; all pass with this change.test_append_without_optional_partition_source_columnsintests/catalog/test_catalog_behaviors.pyappends input without an optional column, a struct field and a whole struct, with identity and bucket partitions on each, and checks the rows, the null partition and anIS NULLscan.test_append_without_optional_binary_partition_sourceintests/io/test_pyarrow.pydoes the same for a binary column with a truncate partition. Both fail on main with theKeyErrororArrowInvalidabove and pass with this change.Are there any user-facing changes?
Yes, writes to tables partitioned on a nested field with a dot in a name on its path work, partition values match the written data when the input has field IDs from before a rename, and an append without an optional partition source column puts the rows in the null partition instead of raising.
Please add the
changeloglabel.This pull request and its description were written by Isaac.