|
31 | 31 | from pytest_mock.plugin import MockerFixture
|
32 | 32 |
|
33 | 33 | from pyiceberg.catalog import Catalog
|
34 |
| -from pyiceberg.exceptions import NoSuchTableError |
| 34 | +from pyiceberg.exceptions import NoSuchTableError, CommitFailedException |
35 | 35 | from pyiceberg.io import FileIO
|
36 | 36 | from pyiceberg.io.pyarrow import UnsupportedPyArrowTypeException, _pyarrow_schema_ensure_large_types
|
37 | 37 | from pyiceberg.manifest import DataFile
|
@@ -903,3 +903,61 @@ def test_add_files_that_referenced_by_current_snapshot_with_check_duplicate_file
|
903 | 903 | with pytest.raises(ValueError) as exc_info:
|
904 | 904 | tbl.add_files(file_paths=[existing_files_in_table], check_duplicate_files=True)
|
905 | 905 | assert f"Cannot add files that are already referenced by table, files: {existing_files_in_table}" in str(exc_info.value)
|
| 906 | + |
| 907 | +@pytest.mark.integration |
| 908 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 909 | +def test_conflict_delete_delete( |
| 910 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 911 | +) -> None: |
| 912 | + identifier = "default.test_conflict" |
| 913 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": "1"}, [arrow_table_with_null]) |
| 914 | + tbl2 = session_catalog.load_table(identifier) |
| 915 | + |
| 916 | + tbl1.delete("string == 'z'") |
| 917 | + |
| 918 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 919 | + # tbl2 isn't aware of the commit by tbl1 |
| 920 | + tbl2.delete("string == 'z'") |
| 921 | + |
| 922 | + |
| 923 | +@pytest.mark.integration |
| 924 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 925 | +def test_conflict_delete_append( |
| 926 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 927 | +) -> None: |
| 928 | + identifier = "default.test_conflict" |
| 929 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": "1"}, [arrow_table_with_null]) |
| 930 | + tbl2 = session_catalog.load_table(identifier) |
| 931 | + |
| 932 | + # This is allowed |
| 933 | + tbl1.delete("string == 'z'") |
| 934 | + tbl2.append(arrow_table_with_null) |
| 935 | + |
| 936 | + |
| 937 | +@pytest.mark.integration |
| 938 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 939 | +def test_conflict_append_delete( |
| 940 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 941 | +) -> None: |
| 942 | + identifier = "default.test_conflict" |
| 943 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": "1"}, [arrow_table_with_null]) |
| 944 | + tbl2 = session_catalog.load_table(identifier) |
| 945 | + |
| 946 | + tbl1.delete("string == 'z'") |
| 947 | + |
| 948 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 949 | + # tbl2 isn't aware of the commit by tbl1 |
| 950 | + tbl2.delete("string == 'z'") |
| 951 | + |
| 952 | + |
| 953 | +@pytest.mark.integration |
| 954 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 955 | +def test_conflict_append_append( |
| 956 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 957 | +) -> None: |
| 958 | + identifier = "default.test_conflict" |
| 959 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": "1"}, [arrow_table_with_null]) |
| 960 | + tbl2 = session_catalog.load_table(identifier) |
| 961 | + |
| 962 | + tbl1.append(arrow_table_with_null) |
| 963 | + tbl2.append(arrow_table_with_null) |
0 commit comments