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


##########
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, 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)
+
+    with table.update_spec() as update:
+        update.add_field(source_column_name="VendorID", 
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:
   can we now just compare the partition specs?



##########
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, 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)
+
+    with table.update_spec() as update:
+        update.add_field(source_column_name="VendorID", 
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")

Review Comment:
   nit: is it conflicting or concurrent here? test name is _conflict :) 



##########
tests/integration/test_catalog.py:
##########
@@ -98,6 +102,9 @@ def hive_catalog() -> Generator[Catalog, None, None]:
 ]
 
 
+SIMPLE_SCHEMA = Schema(NestedField(1, "id", LongType(), required=True), 
NestedField(2, "data", StringType(), required=False))

Review Comment:
   nit: can we just reuse the `test_schema: Schema` from conftest? 



-- 
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