rahulsmahadev opened a new pull request, #4616:
URL: https://github.com/apache/iceberg-python/pull/4616

   # 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:
   
   ```python
   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": ["[email protected]"], "n": [2]}))
   # the new data file stores a value count and the lower bound 
b'[email protected]' 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.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to