Skip to content

Commit

Permalink
[Bug fix] update name mapping in Transaction.update_schema (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungwy authored Mar 10, 2024
1 parent 70342ac commit a222825
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/test_rest_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,17 +672,21 @@ 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],
)

# 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']),
])

Expand Down

0 comments on commit a222825

Please sign in to comment.