|
24 | 24 |
|
25 | 25 | from pyiceberg.catalog.rest import RestCatalog
|
26 | 26 | from pyiceberg.exceptions import NoSuchTableError
|
27 |
| -from pyiceberg.expressions import AlwaysTrue, EqualTo |
| 27 | +from pyiceberg.expressions import AlwaysTrue, EqualTo, LessThanOrEqual |
28 | 28 | from pyiceberg.manifest import ManifestEntryStatus
|
29 | 29 | from pyiceberg.partitioning import PartitionField, PartitionSpec
|
30 | 30 | from pyiceberg.schema import Schema
|
@@ -923,3 +923,55 @@ def test_delete_on_empty_table(spark: SparkSession, session_catalog: RestCatalog
|
923 | 923 |
|
924 | 924 | # Assert that no new snapshot was created because no rows were deleted
|
925 | 925 | assert len(tbl.snapshots()) == 0
|
| 926 | + |
| 927 | + |
| 928 | +@pytest.mark.integration |
| 929 | +def test_manifest_entry_after_deletes(session_catalog: RestCatalog) -> None: |
| 930 | + identifier = "default.test_manifest_entry_after_deletes" |
| 931 | + try: |
| 932 | + session_catalog.drop_table(identifier) |
| 933 | + except NoSuchTableError: |
| 934 | + pass |
| 935 | + |
| 936 | + schema = pa.schema( |
| 937 | + [ |
| 938 | + ("id", pa.int32()), |
| 939 | + ("name", pa.string()), |
| 940 | + ] |
| 941 | + ) |
| 942 | + |
| 943 | + table = session_catalog.create_table(identifier, schema) |
| 944 | + data = pa.Table.from_pylist( |
| 945 | + [ |
| 946 | + {"id": 1, "name": "foo"}, |
| 947 | + {"id": 2, "name": "bar"}, |
| 948 | + {"id": 3, "name": "bar"}, |
| 949 | + {"id": 4, "name": "bar"}, |
| 950 | + ], |
| 951 | + schema=schema, |
| 952 | + ) |
| 953 | + table.append(data) |
| 954 | + |
| 955 | + def assert_manifest_entry(expected_status: ManifestEntryStatus, expected_snapshot_id: int) -> None: |
| 956 | + current_snapshot = table.refresh().current_snapshot() |
| 957 | + assert current_snapshot is not None |
| 958 | + |
| 959 | + manifest_files = current_snapshot.manifests(table.io) |
| 960 | + assert len(manifest_files) == 1 |
| 961 | + |
| 962 | + entries = manifest_files[0].fetch_manifest_entry(table.io, discard_deleted=False) |
| 963 | + assert len(entries) == 1 |
| 964 | + entry = entries[0] |
| 965 | + assert entry.status == expected_status |
| 966 | + assert entry.snapshot_id == expected_snapshot_id |
| 967 | + |
| 968 | + before_delete_snapshot = table.current_snapshot() |
| 969 | + assert before_delete_snapshot is not None |
| 970 | + |
| 971 | + assert_manifest_entry(ManifestEntryStatus.ADDED, before_delete_snapshot.snapshot_id) |
| 972 | + |
| 973 | + table.delete(LessThanOrEqual("id", 4)) |
| 974 | + after_delete_snapshot = table.refresh().current_snapshot() |
| 975 | + assert after_delete_snapshot is not None |
| 976 | + |
| 977 | + assert_manifest_entry(ManifestEntryStatus.DELETED, after_delete_snapshot.snapshot_id) |
0 commit comments