This is an automated email from the ASF dual-hosted git repository.
honahx pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new a222825d [Bug fix] update name mapping in Transaction.update_schema
(#508)
a222825d is described below
commit a222825df6b009a0dc49ffa896b21932f28c4452
Author: Sung Yun <[email protected]>
AuthorDate: Sat Mar 9 23:41:07 2024 -0700
[Bug fix] update name mapping in Transaction.update_schema (#508)
---
pyiceberg/table/__init__.py | 7 ++++++-
tests/integration/test_rest_schema.py | 8 ++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py
index 76aa533d..b244dfb1 100644
--- a/pyiceberg/table/__init__.py
+++ b/pyiceberg/table/__init__.py
@@ -321,7 +321,12 @@ class Transaction:
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 4c758e4c..7aeb1bcc 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']),
])