|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +import pyarrow as pa |
| 19 | +import pytest |
| 20 | +from pyspark.sql import SparkSession |
| 21 | + |
| 22 | +from pyiceberg.catalog import Catalog |
| 23 | +from pyiceberg.exceptions import CommitFailedException |
| 24 | +from utils import _create_table |
| 25 | + |
| 26 | + |
| 27 | +@pytest.mark.integration |
| 28 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 29 | +def test_conflict_delete_delete( |
| 30 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 31 | +) -> None: |
| 32 | + """This test should start passing once optimistic concurrency control has been implemented.""" |
| 33 | + identifier = "default.test_conflict" |
| 34 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": format_version}, [arrow_table_with_null]) |
| 35 | + tbl2 = session_catalog.load_table(identifier) |
| 36 | + |
| 37 | + tbl1.delete("string == 'z'") |
| 38 | + |
| 39 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 40 | + # tbl2 isn't aware of the commit by tbl1 |
| 41 | + tbl2.delete("string == 'z'") |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.integration |
| 45 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 46 | +def test_conflict_delete_append( |
| 47 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 48 | +) -> None: |
| 49 | + """This test should start passing once optimistic concurrency control has been implemented.""" |
| 50 | + identifier = "default.test_conflict" |
| 51 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": format_version}, [arrow_table_with_null]) |
| 52 | + tbl2 = session_catalog.load_table(identifier) |
| 53 | + |
| 54 | + # This is allowed |
| 55 | + tbl1.delete("string == 'z'") |
| 56 | + |
| 57 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 58 | + # tbl2 isn't aware of the commit by tbl1 |
| 59 | + tbl2.append(arrow_table_with_null) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.mark.integration |
| 63 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 64 | +def test_conflict_append_delete( |
| 65 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 66 | +) -> None: |
| 67 | + """This test should start passing once optimistic concurrency control has been implemented.""" |
| 68 | + identifier = "default.test_conflict" |
| 69 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": format_version}, [arrow_table_with_null]) |
| 70 | + tbl2 = session_catalog.load_table(identifier) |
| 71 | + |
| 72 | + tbl1.append(arrow_table_with_null) |
| 73 | + |
| 74 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 75 | + # tbl2 isn't aware of the commit by tbl1 |
| 76 | + tbl2.delete("string == 'z'") |
| 77 | + |
| 78 | + |
| 79 | +@pytest.mark.integration |
| 80 | +@pytest.mark.parametrize("format_version", [1, 2]) |
| 81 | +def test_conflict_append_append( |
| 82 | + spark: SparkSession, session_catalog: Catalog, arrow_table_with_null: pa.Table, format_version: int |
| 83 | +) -> None: |
| 84 | + """This test should start passing once optimistic concurrency control has been implemented.""" |
| 85 | + identifier = "default.test_conflict" |
| 86 | + tbl1 = _create_table(session_catalog, identifier, {"format-version": format_version}, [arrow_table_with_null]) |
| 87 | + tbl2 = session_catalog.load_table(identifier) |
| 88 | + |
| 89 | + tbl1.append(arrow_table_with_null) |
| 90 | + |
| 91 | + with pytest.raises(CommitFailedException, match="(branch main has changed: expected id ).*"): |
| 92 | + # tbl2 isn't aware of the commit by tbl1 |
| 93 | + tbl2.append(arrow_table_with_null) |
0 commit comments