Skip to content

Fix append when a data column is named like a partition helper column - #4344

Merged
Fokko merged 2 commits into
apache:mainfrom
rahulsmahadev:rahul/partition-helper-column-collision
Nov 11, 2026
Merged

Fokko merged 2 commits into
apache:mainfrom
rahulsmahadev:rahul/partition-helper-column-collision

Conversation

@rahulsmahadev

Copy link
Copy Markdown
Contributor

Rationale for this change

_determine_partitions adds the transformed partition values to the Arrow table as temporary columns named _partition_<partition field name>. If the data already has a column with that name, the lookup by name is ambiguous and append() fails:

schema = Schema(
    NestedField(1, "id", LongType()),
    NestedField(2, "_partition_region", StringType()),
    NestedField(3, "region", StringType()),
)
spec = PartitionSpec(PartitionField(source_id=3, field_id=1000, transform=IdentityTransform(), name="region"))
table = catalog.create_table("default.t", schema=schema, partition_spec=spec)
table.append(pa.table({"id": [1], "_partition_region": ["a"], "region": ["us"]}))
# KeyError: 'Field "_partition_region" exists 2 times in schema'

This change picks helper column names that are not already in the table, by prefixing underscores until the name is free. The helper columns are still dropped before the data files are written.

Are these changes tested?

Yes. test_determine_partitions_with_column_named_like_partition_helper in tests/io/test_pyarrow.py partitions a table that has a _partition_region data column and checks that every row lands in the right partition with that column unchanged. It fails without the fix.

Are there any user-facing changes?

Bug fix only: appends to such tables now succeed. No API changes.

This pull request and its description were written by Isaac.

rahulsmahadev and others added 2 commits November 10, 2026 23:52
_determine_partitions adds the transformed partition values as columns named
_partition_<field name>. A data column with the same name made the column
lookup ambiguous and the append raised KeyError. Pick helper names that are
not already in the table.

Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@rahulsmahadev

Copy link
Copy Markdown
Contributor Author

@geruh @DG47 could you take a look when you have a chance? It changes how _determine_partitions names its helper partition columns, which you both worked on in #2204 and #4121.

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like an edge case, but reasonable to add. Thanks @rahulsmahadev

@Fokko
Fokko added this pull request to the merge queue Nov 11, 2026
Merged via the queue into apache:main with commit 640c414 Nov 11, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants