Fokko commented on code in PR #8174:
URL: https://github.com/apache/iceberg/pull/8174#discussion_r1300183129
##########
python/pyiceberg/table/__init__.py:
##########
@@ -841,3 +868,239 @@ def to_ray(self) -> ray.data.dataset.Dataset:
import ray
return ray.data.from_arrow(self.to_arrow())
+
+
+class UpdateSchema:
+ def __init__(self, schema: Schema, table: Optional[Table] = None,
last_column_id: Optional[int] = None):
+ self._table = table
+ self._schema = schema
+ if last_column_id:
+ self._last_column_id = itertools.count(last_column_id + 1)
+ else:
+ self._last_column_id = itertools.count(schema.highest_field_id + 1)
+
+ self._identifier_field_names = schema.column_names
+ self._adds: Dict[int, List[NestedField]] = {}
+ self._added_name_to_id: Dict[str, int] = {}
+ self._id_to_parent: Dict[int, str] = {}
+ self._allow_incompatible_changes: bool = False
+ self._case_sensitive: bool = True
+
+ def __exit__(self, _: Any, value: Any, traceback: Any) -> None:
Review Comment:
The reference to the table is refreshed:
```python
table_update_response = self._table.catalog._commit_table( #
pylint: disable=W0212
CommitTableRequest(
identifier=self._table.identifier[1:],
updates=[
AddSchemaUpdate(schema=new_schema,
last_column_id=new_schema.highest_field_id),
SetCurrentSchemaUpdate(schema_id=-1),
],
)
)
self._table.metadata = table_update_response.metadata
self._table.metadata_location =
table_update_response.metadata_location
```
So strictly it is not needed, and the table is already updated. I noticed
this when checking the integration tests. With the context manager this is
indeed not possible, I'm also fine with leaving this out.
--
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]