fix: Allow update_column to change required for list elements and map values#2798
Conversation
… values Closes apache#2786 The `update_schema().update_column()` method was not updating the `required` property for list elements or map values. The `_ApplyChanges` visitor's `list()` and `map()` methods always used the original `element_required` and `value_required` values without checking for updates in `self._updates`. This fix modifies both methods to check `self._updates` for the element/value field ID and use the updated `required` value if present.
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where update_schema().update_column() was not properly updating the required property for list elements and map values. The fix modifies the _ApplyChanges visitor class to check for updates to these nested fields and apply the required property accordingly.
Changes:
- Modified
_ApplyChanges.list()method to checkself._updatesfor element's required property updates - Modified
_ApplyChanges.map()method to checkself._updatesfor value's required property updates - Added comprehensive unit tests for both list element and map value required property updates
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyiceberg/table/update/schema.py | Fixed list() and map() methods to properly apply required property updates from self._updates dictionary |
| tests/table/test_init.py | Added two new unit tests to verify list element and map value required property can be updated |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Update element to required | ||
| update2 = UpdateSchema(transaction=table_v2.transaction(), schema=schema_with_list) | ||
| update2._allow_incompatible_changes = True # Allow optional -> required |
There was a problem hiding this comment.
thanks for adding this
optional -> required is incompatible and thus requires the flag
iceberg-python/pyiceberg/table/update/schema.py
Lines 368 to 369 in bad9cda
<!--
Thanks for opening a pull request!
-->
<!-- In the case this PR will resolve an issue, please replace
${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
<!-- Closes #${GITHUB_ISSUE_ID} -->
# Rationale for this change
Follow up to #2798
More test coverages
## Are these changes tested?
## Are there any user-facing changes?
<!-- In the case of user-facing changes, please add the changelog label.
-->
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
update_schema().update_column()was not updating therequiredproperty for list elements or map values_ApplyChanges.list()to checkself._updatesfor element's required property_ApplyChanges.map()to checkself._updatesfor value's required propertyTest plan
Closes #2786