smaheshwar-pltr commented on code in PR #3220:
URL: https://github.com/apache/iceberg-python/pull/3220#discussion_r3262304113


##########
tests/integration/test_rest_catalog.py:
##########
@@ -69,6 +72,81 @@ def test_create_namespace_if_already_existing(catalog: 
RestCatalog) -> None:
     assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER)
 
 
[email protected]
[email protected]("catalog", [lf("session_catalog")])
+def test_replace_table_end_to_end_against_rest_server(catalog: Catalog) -> 
None:
+    """End-to-end smoke test: replace_table against a real REST server.
+
+    Detailed replace_table semantics are covered against InMemoryCatalog and 
SqlCatalog in
+    `tests/catalog/test_catalog_behaviors.py`. This test verifies the REST 
wire path: server
+    accepts the commit, preserves the UUID, and clears the current snapshot."""
+    identifier = f"default.test_replace_table_e2e_{catalog.name}"
+    if not catalog.namespace_exists("default"):
+        catalog.create_namespace("default")
+    if catalog.table_exists(identifier):
+        catalog.drop_table(identifier)
+
+    original_schema = Schema(
+        NestedField(field_id=1, name="id", field_type=LongType(), 
required=False),
+        NestedField(field_id=2, name="data", field_type=StringType(), 
required=False),
+    )
+    original = catalog.create_table(identifier, schema=original_schema)
+    original.append(
+        pa.Table.from_pydict(
+            {"id": [1, 2, 3], "data": ["a", "b", "c"]},
+            schema=pa.schema([pa.field("id", pa.int64()), pa.field("data", 
pa.large_string())]),
+        )
+    )
+    original.refresh()
+    original_snapshot_id = original.current_snapshot().snapshot_id  # type: 
ignore[union-attr]
+
+    new_schema = Schema(
+        NestedField(field_id=1, name="id", field_type=LongType(), 
required=False),
+        NestedField(field_id=2, name="name", field_type=StringType(), 
required=False),
+        NestedField(field_id=3, name="active", field_type=BooleanType(), 
required=False),
+    )
+    replaced = catalog.replace_table(identifier, schema=new_schema)
+
+    assert replaced.metadata.table_uuid == original.metadata.table_uuid
+    assert replaced.current_snapshot() is None
+    assert any(s.snapshot_id == original_snapshot_id for s in 
replaced.metadata.snapshots)
+    catalog.drop_table(identifier)
+
+
[email protected]
[email protected]("catalog", [lf("session_catalog")])
+def test_replace_table_transaction_rtas_against_rest_server(catalog: Catalog) 
-> None:
+    """RTAS (Replace Table As Select) against a real REST server: the schema 
swap and the
+    new-data write must land atomically — the new snapshot is current on 
commit."""

Review Comment:
   ```suggestion
   def test_replace_table_transactioncatalog: Catalog) -> None:
   ```



##########
tests/integration/test_rest_catalog.py:
##########
@@ -69,6 +72,81 @@ def test_create_namespace_if_already_existing(catalog: 
RestCatalog) -> None:
     assert catalog.namespace_exists(TEST_NAMESPACE_IDENTIFIER)
 
 
[email protected]
[email protected]("catalog", [lf("session_catalog")])
+def test_replace_table_end_to_end_against_rest_server(catalog: Catalog) -> 
None:
+    """End-to-end smoke test: replace_table against a real REST server.
+
+    Detailed replace_table semantics are covered against InMemoryCatalog and 
SqlCatalog in
+    `tests/catalog/test_catalog_behaviors.py`. This test verifies the REST 
wire path: server
+    accepts the commit, preserves the UUID, and clears the current snapshot."""
+    identifier = f"default.test_replace_table_e2e_{catalog.name}"
+    if not catalog.namespace_exists("default"):
+        catalog.create_namespace("default")
+    if catalog.table_exists(identifier):
+        catalog.drop_table(identifier)
+
+    original_schema = Schema(
+        NestedField(field_id=1, name="id", field_type=LongType(), 
required=False),
+        NestedField(field_id=2, name="data", field_type=StringType(), 
required=False),
+    )
+    original = catalog.create_table(identifier, schema=original_schema)
+    original.append(
+        pa.Table.from_pydict(
+            {"id": [1, 2, 3], "data": ["a", "b", "c"]},
+            schema=pa.schema([pa.field("id", pa.int64()), pa.field("data", 
pa.large_string())]),
+        )
+    )
+    original.refresh()
+    original_snapshot_id = original.current_snapshot().snapshot_id  # type: 
ignore[union-attr]
+
+    new_schema = Schema(
+        NestedField(field_id=1, name="id", field_type=LongType(), 
required=False),
+        NestedField(field_id=2, name="name", field_type=StringType(), 
required=False),
+        NestedField(field_id=3, name="active", field_type=BooleanType(), 
required=False),
+    )
+    replaced = catalog.replace_table(identifier, schema=new_schema)
+
+    assert replaced.metadata.table_uuid == original.metadata.table_uuid
+    assert replaced.current_snapshot() is None
+    assert any(s.snapshot_id == original_snapshot_id for s in 
replaced.metadata.snapshots)
+    catalog.drop_table(identifier)
+
+
[email protected]
[email protected]("catalog", [lf("session_catalog")])
+def test_replace_table_transaction_rtas_against_rest_server(catalog: Catalog) 
-> None:
+    """RTAS (Replace Table As Select) against a real REST server: the schema 
swap and the
+    new-data write must land atomically — the new snapshot is current on 
commit."""

Review Comment:
   ```suggestion
   def test_replace_table_transaction(catalog: Catalog) -> None:
   ```



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