Fokko commented on code in PR #4392:
URL: https://github.com/apache/iceberg-python/pull/4392#discussion_r4630570110
##########
tests/table/test_upsert.py:
##########
@@ -427,6 +427,59 @@ def test_upsert_into_empty_table(catalog: Catalog) -> None:
assert upd.rows_inserted == 4
+def test_upsert_retry_with_a_concurrently_inserted_key(catalog: Catalog) ->
None:
+ identifier = "default.test_upsert_retry_with_a_concurrently_inserted_key"
+ _drop_table(catalog, identifier)
+
+ schema = Schema(
+ NestedField(1, "k", LongType(), required=True),
+ NestedField(2, "v", StringType(), required=False),
+ identifier_field_ids=[1],
+ )
+ arrow_schema = schema_to_pyarrow(schema)
+ catalog.create_table(identifier,
schema=schema).append(pa.Table.from_pylist([{"k": 1, "v": "a"}],
schema=arrow_schema))
+
+ writer_a = catalog.load_table(identifier)
+ writer_b = catalog.load_table(identifier)
+ writer_b.upsert(pa.Table.from_pylist([{"k": 2, "v": "b"}],
schema=arrow_schema))
+
+ with pytest.raises(ValidationException):
+ writer_a.upsert(pa.Table.from_pylist([{"k": 2, "v": "a"}],
schema=arrow_schema))
+
+ assert
sorted(catalog.load_table(identifier).scan().to_arrow().to_pylist(), key=str)
== [
+ {"k": 1, "v": "a"},
+ {"k": 2, "v": "b"},
+ ]
+
+
+def
test_upsert_retry_under_snapshot_isolation_does_not_validate_inserted_keys(catalog:
Catalog) -> None:
Review Comment:
Let's add one more test for completeness
```suggestion
def test_upsert_retry_with_a_concurrently_inserted_different_key(catalog:
Catalog) -> None:
identifier =
"default.test_upsert_retry_with_a_concurrently_inserted_different_key"
_drop_table(catalog, identifier)
schema = Schema(
NestedField(1, "k", LongType(), required=True),
NestedField(2, "v", StringType(), required=False),
identifier_field_ids=[1],
)
arrow_schema = schema_to_pyarrow(schema)
catalog.create_table(identifier,
schema=schema).append(pa.Table.from_pylist([{"k": 1, "v": "a"}],
schema=arrow_schema))
writer_a = catalog.load_table(identifier)
writer_b = catalog.load_table(identifier)
writer_b.upsert(pa.Table.from_pylist([{"k": 3, "v": "b"}],
schema=arrow_schema))
writer_a.upsert(pa.Table.from_pylist([{"k": 2, "v": "a"}],
schema=arrow_schema))
assert
sorted(catalog.load_table(identifier).scan().to_arrow().to_pylist(), key=str)
== [
{"k": 1, "v": "a"},
{"k": 2, "v": "a"},
{"k": 3, "v": "b"},
]
def
test_upsert_retry_under_snapshot_isolation_does_not_validate_inserted_keys(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]