Repository navigation
Find partition source columns the same way as the writer - #4457
Closed
rahulsmahadev wants to merge 6 commits into
Closed
rahulsmahadev wants to merge 6 commits into
rahulsmahadev wants to merge 6 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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
rahulsmahadev
marked this pull request as draft
December 1, 2026 02:16
Take the names on the source's struct path by ID from the input schema, and return nulls of the writer's type for a missing field (the truncate large_binary gap is apache/iceberg-rust#3119). ArrowAccessor is not called directly: StructArray.field() ignores struct nulls, and its pa.Table branch combines chunks, which overflows for string sources over 2 GiB. Trim duplicate tests. Co-authored-by: Isaac <no-reply@databricks.com>
Partition values must come from the values write_file stores. Instead of re-deriving its field resolution by hand, project the partition sources per batch with _to_requested_schema, as write_file does (field IDs of the input schema, nulls for missing optional fields, the same casts), and read each source by position with Schema.accessor_for_field. This also fixes ns timestamps and times with the downcast option (apache#4479) and s/ms timestamp and narrow-int inputs (apache#4421); the three tests of apache#4479 move here. Co-authored-by: Isaac <no-reply@databricks.com>
The writer widens float16 to the column's float type, and the partition values now come from that projection, so the append no longer raises ArrowNotImplementedError. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
Closing this to keep my open PRs to the ones worth review time right now. The branch stays available; I can reopen a narrower version or file an issue instead if that would help. |
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_partitionslooks up a partition source in the input by its table name split on dots, but the writer takes each field by ID, with the name it has in the input. An input with field IDs from before a rename is then partitioned on another column:A partition on
cin a struct nameda.braisesKeyError: 'Field "a" does not exist in schema', and one on an optional columnregionthat the input leaves out, which the writer accepts since #921 and stores as nulls, raisesKeyError: 'Field "region" does not exist in schema'. The partition values are also computed before the writer's casts: withdowncast-ns-timestamp-to-us-on-writeon, an identity partition on atimestamp[ns]column writes one row twice and drops another (#4479); bucket, day and hour partitions ontimestamp[s]ortimestamp[ms]inputs and bucket and truncate partitions on int8/int16 inputs raise aValueErrorfrom pyiceberg-core (#4421); and an identity partition on afloat16input raisesArrowNotImplementedError.Fix: project the partition source columns per batch with the writer's
_to_requested_schema(the table schema pruned to the sources withprune_columns) and read each source by position withSchema.accessor_for_field, like Java'sPartitionKeyreads rows throughaccessorForFieldon the write schema. The partition values are then computed from the values the writer stores: renamed, missing (nulls) and cast columns alike, so this also covers #4479 (timestamp[ns]downcast) and thetimestamp[s],timestamp[ms]and narrow-int cases of #4421.#4479 closes in favour of this PR and its tests moved here; the
uint64,large_binaryandbinary_viewcases of #4421 are not covered (see below).Java raises
Cannot build accessor for fieldwhen a source is missing from the write schema (StructTransform); PyIceberg accepts that input since #921, so the rows go to the null partition.Not covered here:
large_binarysupport (truncate transform rejects binary values in transform_literal and LargeBinary arrays iceberg-rust#3119), the same as for alarge_binaryorbinary_viewinput.uint64input for a long column still raise aValueErrorfrom pyiceberg-core.dynamic_partition_overwritestill deletes by the leaf name of a nested source (dynamic_partition_overwritebyidentity(s.x)deletes rows by top-levelx#4196, open fix Use the full column name in the dynamic_partition_overwrite delete filter #4204)._ConvertToArrowExpression._get_field_namestill splits names on dots, so a delete that rewrites a file and a filtered scan of anadd_filesfile raiseArrowInvalidfor a dotted struct name.Are these changes tested?
Yes,
test_append_to_identity_partitioned_table_with_dotted_names,test_append_with_field_ids_after_swapping_column_namesandtest_append_without_optional_partition_source_columnsintests/catalog/test_catalog_behaviors.pyfail on main with theKeyErrors and theypartition above; intests/io/test_pyarrow.py,test_append_partitioned_ns_timestamp_downcast(identity, hour and day) andtest_append_partitioned_ns_time_downcastfail on main withZeroDivisionErrorandtest_append_partitioned_float16_is_widenedwithArrowNotImplementedError; all pass with this change.test_determine_partitions_native_ns_timestamp_is_not_downcastchecks that v3 nanosecond sources are not downcast.Are there any user-facing changes?
Yes, partitioned appends work with dotted struct names, without optional source columns and with the inputs the writer casts (nanosecond timestamps and times with the downcast option, second and millisecond timestamps, narrow integers, half-precision floats, binary for a string column), and take the partition value from the right column when the input has field IDs from before a rename. Files written before this change keep their partition values, so a filtered scan can still skip their rows.
Please add the
changeloglabel.This pull request and its description were written by Isaac.