Skip to content

Keep per-column properties in sync when renaming or dropping columns - #4616

Open
rahulsmahadev wants to merge 4 commits into
apache:mainfrom
rahulsmahadev:rahul/schema-update-metrics-properties
Open

rahulsmahadev wants to merge 4 commits into
apache:mainfrom
rahulsmahadev:rahul/schema-update-metrics-properties

Conversation

@rahulsmahadev

Copy link
Copy Markdown
Contributor

Rationale for this change

Bug: per-column table properties like write.metadata.metrics.column.<name> are keyed by column name, and update_schema() leaves them under the old name. A renamed column loses its metrics mode, and a column added later under a dropped column's name gets the dropped column's mode:

table = catalog.create_table(
    "default.users",
    schema=Schema(NestedField(1, "email", StringType()), NestedField(2, "n", LongType())),
    properties={"write.metadata.metrics.column.email": "none"},
)
with table.update_schema() as update:
    update.rename_column("email", "contact_email")
print(table.properties)
# {'write.metadata.metrics.column.email': 'none'}
table.append(pa.table({"contact_email": ["bob@example.com"], "n": [2]}))
# the new data file stores a value count and the lower bound b'bob@example.com' for contact_email

This affects tables with a metrics mode or bloom filter set on a column that PyIceberg renames or drops. A stale metrics key also makes later Java property updates on the table, such as Spark's ALTER TABLE ... SET TBLPROPERTIES, fail with Invalid metrics config, could not find column email ....

Fix: when UpdateSchema commits, move each per-column property to its column's new full name, or remove it when the column is gone, nested fields of a renamed or dropped struct included. This ports PropertyUtil.applySchemaChanges, which Java's SchemaUpdate runs on commit (the step Spark's ALTER TABLE ... RENAME COLUMN and DROP COLUMN go through), with the same 8 prefixes (TableProperties.COLUMN_PROPERTY_PREFIXES). This is Java main since apache/iceberg#18885 and not released yet; 1.12.0 syncs 3 of the prefixes, for the renamed or dropped column only. PyIceberg's writer only applies write.metadata.metrics.column.; the others are kept in sync for engines that read them from the same table.

Difference from Java main:

  • When a column has both its full-name key and a short-name key (points.lat for points.element.lat), the full-name key, which the writers apply, wins on rename; Java's helper keeps whichever it reads last. A short-name key alone moves to the full name, as in Java, so writers start to apply it.

Are these changes tested?

Yes, added test_update_schema_moves_column_properties, test_update_schema_column_properties_in_transaction (all 8 prefixes, renames into a dropped column's name and onto a key that matches no column, a key that differs from a column only by case, properties set earlier in the same transaction) and test_update_schema_prefers_full_name_column_property (both key orders, checked through the written metrics, and a short-name key alone) to tests/table/test_init.py, for each catalog of the catalog fixture. All three fail on main, where the properties keep their old names, and pass with this change.

Are there any user-facing changes?

Yes, renaming or dropping a column now renames or removes its per-column table properties, and TableProperties gets COLUMN_PROPERTY_PREFIXES plus constants for the six Java per-column Parquet prefixes it was missing.

Please add the changelog label.

This pull request and its description were written by Isaac.

rahulsmahadev and others added 4 commits December 2, 2026 17:55
update_schema() left properties keyed by column name, such as
write.metadata.metrics.column.<name>, under the old name: a renamed column lost its
metrics mode, and a column added under a dropped column's name inherited it.
UpdateSchema now moves them to the column's new full name, or removes them when the
column is gone, as Java's SchemaUpdate does (apache/iceberg#18885).

Co-authored-by: Isaac <no-reply@databricks.com>
A field in a list or map can have a full-name key (points.element.lat) and a short-name
key (points.lat). A rename moved both to the same new key and the one read last won,
which could change the mode the writer applies. Use the full-name key's value, and pin
the case-sensitive key lookup and a rename onto an unresolved key in the tests.

Co-authored-by: Isaac <no-reply@databricks.com>
A short-name key such as points.lat with no full-name key next to it
moves to the full name on rename, as Java's helper does.

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

@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.

Nice find, and solid port of Java's PropertyUtil.applySchemaChanges @rahulsmahadev! Verified that the 8 prefixes in COLUMN_PROPERTY_PREFIXES match Java main exactly, and that the added tests fail on main. The full-name key taking precedence over a short-name key is a sane difference too. 🚀

This branch has not been deployed

No deployments
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