This is an automated email from the ASF dual-hosted git repository.

sungwy 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 40357476 Bug Fix: Use historical partition field name (#1161)
40357476 is described below

commit 40357476ad0a79f7486b96a6e29b404bc699b70d
Author: Sung Yun <[email protected]>
AuthorDate: Thu Sep 12 08:16:33 2024 -0400

    Bug Fix: Use historical partition field name (#1161)
    
    * use historical partition field name
    
    * thanks ndrluis!
---
 pyiceberg/table/update/spec.py                | 10 ++++-----
 tests/integration/test_partition_evolution.py | 32 +++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/pyiceberg/table/update/spec.py b/pyiceberg/table/update/spec.py
index aaa0e138..b732b211 100644
--- a/pyiceberg/table/update/spec.py
+++ b/pyiceberg/table/update/spec.py
@@ -275,12 +275,12 @@ class UpdateSpec(UpdateTableMetadata["UpdateSpec"]):
             historical_fields = []
             for spec in self._transaction.table_metadata.specs().values():
                 for field in spec.fields:
-                    historical_fields.append((field.source_id, field.field_id, 
repr(field.transform), field.name))
+                    historical_fields.append(field)
 
-            for field_key in historical_fields:
-                if field_key[0] == source_id and field_key[2] == 
repr(transform):
-                    if name is None or field_key[3] == name:
-                        return PartitionField(source_id, field_key[1], 
transform, name)
+            for field in historical_fields:
+                if field.source_id == source_id and repr(field.transform) == 
repr(transform):
+                    if name is None or field.name == name:
+                        return PartitionField(source_id, field.field_id, 
transform, field.name)
 
         new_field_id = self._new_field_id()
         if name is None:
diff --git a/tests/integration/test_partition_evolution.py 
b/tests/integration/test_partition_evolution.py
index 5cc7512f..805c0c1f 100644
--- a/tests/integration/test_partition_evolution.py
+++ b/tests/integration/test_partition_evolution.py
@@ -207,6 +207,38 @@ def test_remove_identity_v2(catalog: Catalog) -> None:
     assert table_v2.spec() == PartitionSpec(spec_id=0)
 
 
[email protected]
[email protected]("catalog", 
[pytest.lazy_fixture("session_catalog_hive"), 
pytest.lazy_fixture("session_catalog")])
+def test_remove_and_add_identity(catalog: Catalog) -> None:
+    table = _table(catalog)
+    table.update_spec().add_identity("id").commit()
+    table.update_spec().remove_field("id").commit()
+    table.update_spec().add_identity("id").commit()
+
+    assert len(table.specs()) == 4
+    assert table.spec().spec_id == 3
+    assert table.spec() == PartitionSpec(
+        PartitionField(source_id=1, field_id=1000, transform=VoidTransform(), 
name="id_1000"),
+        PartitionField(source_id=1, field_id=1001, 
transform=IdentityTransform(), name="id"),
+        spec_id=3,
+    )
+
+
[email protected]
[email protected]("catalog", 
[pytest.lazy_fixture("session_catalog_hive"), 
pytest.lazy_fixture("session_catalog")])
+def test_remove_and_add_identity_v2(catalog: Catalog) -> None:
+    table_v2 = _table_v2(catalog)
+    table_v2.update_spec().add_identity("id").commit()
+    table_v2.update_spec().remove_field("id").commit()
+    table_v2.update_spec().add_identity("id").commit()
+
+    assert len(table_v2.specs()) == 2
+    assert table_v2.spec().spec_id == 1
+    assert table_v2.spec() == PartitionSpec(
+        PartitionField(source_id=1, field_id=1000, 
transform=IdentityTransform(), name="id"), spec_id=1
+    )
+
+
 @pytest.mark.integration
 @pytest.mark.parametrize("catalog", 
[pytest.lazy_fixture("session_catalog_hive"), 
pytest.lazy_fixture("session_catalog")])
 def test_remove_bucket(catalog: Catalog) -> None:

Reply via email to