Skip to content

Commit 0923dc4

Browse files
committed
add tests for verifying snapshot compatibility
1 parent 611b017 commit 0923dc4

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tests/integration/test_add_files.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from pytest_mock.plugin import MockerFixture
2929

3030
from pyiceberg.catalog import Catalog
31-
from pyiceberg.exceptions import NoSuchTableError
31+
from pyiceberg.exceptions import CommitFailedException, NoSuchTableError
3232
from pyiceberg.io import FileIO
3333
from pyiceberg.io.pyarrow import UnsupportedPyArrowTypeException, _pyarrow_schema_ensure_large_types
3434
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec
@@ -850,3 +850,62 @@ def test_add_files_that_referenced_by_current_snapshot_with_check_duplicate_file
850850
with pytest.raises(ValueError) as exc_info:
851851
tbl.add_files(file_paths=[existing_files_in_table], check_duplicate_files=True)
852852
assert f"Cannot add files that are already referenced by table, files: {existing_files_in_table}" in str(exc_info.value)
853+
854+
855+
@pytest.mark.integration
856+
@pytest.mark.parametrize("format_version", [1, 2])
857+
def test_conflict_delete_delete(
858+
spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int
859+
) -> None:
860+
identifier = "default.test_conflict"
861+
tbl1 = _create_table(session_catalog, identifier, format_version, [arrow_table_with_null])
862+
tbl2 = session_catalog.load_table(identifier)
863+
864+
tbl1.delete("string == 'z'")
865+
866+
with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"):
867+
# tbl2 isn't aware of the commit by tbl1
868+
tbl2.delete("string == 'z'")
869+
870+
871+
@pytest.mark.integration
872+
@pytest.mark.parametrize("format_version", [1, 2])
873+
def test_conflict_delete_append(
874+
spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int
875+
) -> None:
876+
identifier = "default.test_conflict"
877+
tbl1 = _create_table(session_catalog, identifier, format_version, [arrow_table_with_null])
878+
tbl2 = session_catalog.load_table(identifier)
879+
880+
# This is allowed
881+
tbl1.delete("string == 'z'")
882+
tbl2.append(arrow_table_with_null)
883+
884+
885+
@pytest.mark.integration
886+
@pytest.mark.parametrize("format_version", [1, 2])
887+
def test_conflict_append_delete(
888+
spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int
889+
) -> None:
890+
identifier = "default.test_conflict"
891+
tbl1 = _create_table(session_catalog, identifier, format_version, [arrow_table_with_null])
892+
tbl2 = session_catalog.load_table(identifier)
893+
894+
tbl1.append(arrow_table_with_null)
895+
896+
with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"):
897+
# tbl2 isn't aware of the commit by tbl1
898+
tbl2.delete("string == 'z'")
899+
900+
901+
@pytest.mark.integration
902+
@pytest.mark.parametrize("format_version", [1, 2])
903+
def test_conflict_append_append(
904+
spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int
905+
) -> None:
906+
identifier = "default.test_conflict"
907+
tbl1 = _create_table(session_catalog, identifier, format_version, [arrow_table_with_null])
908+
tbl2 = session_catalog.load_table(identifier)
909+
910+
tbl1.append(arrow_table_with_null)
911+
tbl2.append(arrow_table_with_null)

0 commit comments

Comments
 (0)