Skip to content

Commit a222825

Browse files
authored
[Bug fix] update name mapping in Transaction.update_schema (#508)
1 parent 70342ac commit a222825

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pyiceberg/table/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ def update_schema(self, allow_incompatible_changes: bool = False, case_sensitive
321321
Returns:
322322
A new UpdateSchema.
323323
"""
324-
return UpdateSchema(self, allow_incompatible_changes=allow_incompatible_changes, case_sensitive=case_sensitive)
324+
return UpdateSchema(
325+
self,
326+
allow_incompatible_changes=allow_incompatible_changes,
327+
case_sensitive=case_sensitive,
328+
name_mapping=self._table.name_mapping(),
329+
)
325330

326331
def update_snapshot(self) -> UpdateSnapshot:
327332
"""Create a new UpdateSnapshot to produce a new snapshot for the table.

tests/integration/test_rest_schema.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,17 +672,21 @@ def test_rename_simple(simple_table: Table) -> None:
672672
with simple_table.update_schema() as schema_update:
673673
schema_update.rename_column("foo", "vo")
674674

675+
with simple_table.transaction() as txn:
676+
with txn.update_schema() as schema_update:
677+
schema_update.rename_column("bar", "var")
678+
675679
assert simple_table.schema() == Schema(
676680
NestedField(field_id=1, name="vo", field_type=StringType(), required=False),
677-
NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
681+
NestedField(field_id=2, name="var", field_type=IntegerType(), required=True),
678682
NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False),
679683
identifier_field_ids=[2],
680684
)
681685

682686
# Check that the name mapping gets updated
683687
assert simple_table.name_mapping() == NameMapping([
684688
MappedField(field_id=1, names=['foo', 'vo']),
685-
MappedField(field_id=2, names=['bar']),
689+
MappedField(field_id=2, names=['bar', 'var']),
686690
MappedField(field_id=3, names=['baz']),
687691
])
688692

0 commit comments

Comments
 (0)