gabeiglio commented on code in PR #2479:
URL: https://github.com/apache/iceberg-python/pull/2479#discussion_r2365885454


##########
tests/integration/test_catalog.py:
##########
@@ -343,3 +350,64 @@ def test_update_namespace_properties(test_catalog: 
Catalog, database_name: str)
         else:
             assert k in update_report.removed
     assert "updated test description" == 
test_catalog.load_namespace_properties(database_name)["comment"]
+
+
[email protected]
[email protected]("test_catalog", CATALOGS)
+def test_update_table_spec(test_catalog: Catalog, table_name: str, 
database_name: str) -> None:
+    identifier = (database_name, table_name)
+    test_catalog.create_namespace(database_name)
+    table = test_catalog.create_table(identifier, SIMPLE_SCHEMA)

Review Comment:
   Small nit to use the schema provided in conftest.py
   ```suggestion
   def test_update_table_spec(test_catalog: Catalog, test_schema: Schema, 
table_name: str, database_name: str) -> None:
       identifier = (database_name, table_name)
       test_catalog.create_namespace(database_name)
       table = test_catalog.create_table(identifier, test_schema)
   ```



##########
tests/integration/test_catalog.py:
##########
@@ -343,3 +350,64 @@ def test_update_namespace_properties(test_catalog: 
Catalog, database_name: str)
         else:
             assert k in update_report.removed
     assert "updated test description" == 
test_catalog.load_namespace_properties(database_name)["comment"]
+
+
[email protected]
[email protected]("test_catalog", CATALOGS)
+def test_update_table_spec(test_catalog: Catalog, table_name: str, 
database_name: str) -> None:
+    identifier = (database_name, table_name)
+    test_catalog.create_namespace(database_name)
+    table = test_catalog.create_table(identifier, SIMPLE_SCHEMA)
+
+    with table.update_spec() as update:
+        update.add_field(source_column_name="id", 
transform=BucketTransform(16), partition_field_name="shard")
+
+    loaded = test_catalog.load_table(identifier)
+    expected_spec = PartitionSpec(
+        PartitionField(source_id=1, field_id=1000, 
transform=BucketTransform(16), name="shard"), spec_id=1
+    )
+    # The spec ID may not match, so check equality of the fields
+    assert loaded.spec().fields == expected_spec.fields
+
+
[email protected]
[email protected]("test_catalog", CATALOGS)
+def test_update_table_spec_conflict(test_catalog: Catalog, table_name: str, 
database_name: str) -> None:
+    identifier = (database_name, table_name)
+    test_catalog.create_namespace(database_name)
+    spec = PartitionSpec(PartitionField(source_id=1, field_id=1000, 
transform=BucketTransform(16), name="id_bucket"))
+    table = test_catalog.create_table(identifier, SIMPLE_SCHEMA, 
partition_spec=spec)
+
+    update = table.update_spec()
+    update.add_field(source_column_name="data", transform=BucketTransform(16), 
partition_field_name="shard")
+
+    # concurrent update
+    concurrent_table = test_catalog.load_table(identifier)
+    with concurrent_table.update_spec() as concurrent_update:
+        concurrent_update.remove_field("id_bucket")
+
+    with pytest.raises(CommitFailedException, match="Requirement failed: 
default partition spec changed|Cannot commit"):
+        update.commit()
+

Review Comment:
   I think it would be good to also test that `table` remains with the same 
partition spec after failing to commit



##########
tests/integration/test_catalog.py:
##########
@@ -343,3 +350,64 @@ def test_update_namespace_properties(test_catalog: 
Catalog, database_name: str)
         else:
             assert k in update_report.removed
     assert "updated test description" == 
test_catalog.load_namespace_properties(database_name)["comment"]
+
+
[email protected]
[email protected]("test_catalog", CATALOGS)
+def test_update_table_spec(test_catalog: Catalog, table_name: str, 
database_name: str) -> None:
+    identifier = (database_name, table_name)
+    test_catalog.create_namespace(database_name)
+    table = test_catalog.create_table(identifier, SIMPLE_SCHEMA)
+
+    with table.update_spec() as update:
+        update.add_field(source_column_name="id", 
transform=BucketTransform(16), partition_field_name="shard")
+
+    loaded = test_catalog.load_table(identifier)
+    expected_spec = PartitionSpec(
+        PartitionField(source_id=1, field_id=1000, 
transform=BucketTransform(16), name="shard"), spec_id=1
+    )
+    # The spec ID may not match, so check equality of the fields
+    assert loaded.spec().fields == expected_spec.fields

Review Comment:
   Why wouldn't the spec ids match? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to