diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 76aa533d7c..b244dfb16d 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -321,7 +321,12 @@ def update_schema(self, allow_incompatible_changes: bool = False, case_sensitive Returns: A new UpdateSchema. """ - return UpdateSchema(self, allow_incompatible_changes=allow_incompatible_changes, case_sensitive=case_sensitive) + return UpdateSchema( + self, + allow_incompatible_changes=allow_incompatible_changes, + case_sensitive=case_sensitive, + name_mapping=self._table.name_mapping(), + ) def update_snapshot(self) -> UpdateSnapshot: """Create a new UpdateSnapshot to produce a new snapshot for the table. diff --git a/tests/integration/test_rest_schema.py b/tests/integration/test_rest_schema.py index 4c758e4c3e..7aeb1bccdc 100644 --- a/tests/integration/test_rest_schema.py +++ b/tests/integration/test_rest_schema.py @@ -672,9 +672,13 @@ def test_rename_simple(simple_table: Table) -> None: with simple_table.update_schema() as schema_update: schema_update.rename_column("foo", "vo") + with simple_table.transaction() as txn: + with txn.update_schema() as schema_update: + schema_update.rename_column("bar", "var") + assert simple_table.schema() == Schema( NestedField(field_id=1, name="vo", field_type=StringType(), required=False), - NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True), + NestedField(field_id=2, name="var", field_type=IntegerType(), required=True), NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False), identifier_field_ids=[2], ) @@ -682,7 +686,7 @@ def test_rename_simple(simple_table: Table) -> None: # Check that the name mapping gets updated assert simple_table.name_mapping() == NameMapping([ MappedField(field_id=1, names=['foo', 'vo']), - MappedField(field_id=2, names=['bar']), + MappedField(field_id=2, names=['bar', 'var']), MappedField(field_id=3, names=['baz']), ])