|
28 | 28 | from pytest_mock.plugin import MockerFixture |
29 | 29 |
|
30 | 30 | from pyiceberg.catalog import Catalog |
31 | | -from pyiceberg.exceptions import NoSuchTableError |
| 31 | +from pyiceberg.exceptions import CommitFailedException, NoSuchTableError |
32 | 32 | from pyiceberg.io import FileIO |
33 | 33 | from pyiceberg.io.pyarrow import UnsupportedPyArrowTypeException, _pyarrow_schema_ensure_large_types |
34 | 34 | 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 |
850 | 850 | with pytest.raises(ValueError) as exc_info: |
851 | 851 | tbl.add_files(file_paths=[existing_files_in_table], check_duplicate_files=True) |
852 | 852 | 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