Skip to content

Commit 232a436

Browse files
committed
add tests
1 parent 3ce6bbb commit 232a436

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

tests/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from pyiceberg.schema import Accessor, Schema
7171
from pyiceberg.serializers import ToOutputFile
7272
from pyiceberg.table import FileScanTask, Table
73-
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2
73+
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2, TableMetadataV3
7474
from pyiceberg.types import (
7575
BinaryType,
7676
BooleanType,
@@ -917,6 +917,7 @@ def generate_snapshot(
917917
"table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
918918
"location": "s3://bucket/test/location",
919919
"last-sequence-number": 34,
920+
"next-row-id": 1,
920921
"last-updated-ms": 1602638573590,
921922
"last-column-id": 3,
922923
"current-schema-id": 1,
@@ -2381,6 +2382,18 @@ def table_v2(example_table_metadata_v2: Dict[str, Any]) -> Table:
23812382
)
23822383

23832384

2385+
@pytest.fixture
2386+
def table_v3(example_table_metadata_v3: Dict[str, Any]) -> Table:
2387+
table_metadata = TableMetadataV3(**example_table_metadata_v3)
2388+
return Table(
2389+
identifier=("database", "table"),
2390+
metadata=table_metadata,
2391+
metadata_location=f"{table_metadata.location}/uuid.metadata.json",
2392+
io=load_file_io(),
2393+
catalog=NoopCatalog("NoopCatalog"),
2394+
)
2395+
2396+
23842397
@pytest.fixture
23852398
def table_v2_with_fixed_and_decimal_types(
23862399
table_metadata_v2_with_fixed_and_decimal_types: Dict[str, Any],

tests/table/test_init.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,3 +1437,56 @@ def test_remove_partition_statistics_update_with_invalid_snapshot_id(table_v2_wi
14371437
table_v2_with_statistics.metadata,
14381438
(RemovePartitionStatisticsUpdate(snapshot_id=123456789),),
14391439
)
1440+
1441+
def test_add_snapshot_update_fails_without_first_row_id(table_v3: Table) -> None:
1442+
new_snapshot = Snapshot(
1443+
snapshot_id=25,
1444+
parent_snapshot_id=19,
1445+
sequence_number=200,
1446+
timestamp_ms=1602638593590,
1447+
manifest_list="s3:/a/b/c.avro",
1448+
summary=Summary(Operation.APPEND),
1449+
schema_id=3,
1450+
)
1451+
1452+
with pytest.raises(
1453+
ValueError,
1454+
match="Cannot add snapshot without first row id",
1455+
):
1456+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1457+
1458+
1459+
def test_add_snapshot_update_fails_with_smaller_first_row_id(table_v3: Table) -> None:
1460+
new_snapshot = Snapshot(
1461+
snapshot_id=25,
1462+
parent_snapshot_id=19,
1463+
sequence_number=200,
1464+
timestamp_ms=1602638593590,
1465+
manifest_list="s3:/a/b/c.avro",
1466+
summary=Summary(Operation.APPEND),
1467+
schema_id=3,
1468+
first_row_id=0,
1469+
)
1470+
1471+
with pytest.raises(
1472+
ValueError,
1473+
match="Cannot add a snapshot with first row id smaller than the table's next-row-id",
1474+
):
1475+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1476+
1477+
1478+
def test_add_snapshot_update_updates_next_row_id(table_v3: Table) -> None:
1479+
new_snapshot = Snapshot(
1480+
snapshot_id=25,
1481+
parent_snapshot_id=19,
1482+
sequence_number=200,
1483+
timestamp_ms=1602638593590,
1484+
manifest_list="s3:/a/b/c.avro",
1485+
summary=Summary(Operation.APPEND),
1486+
schema_id=3,
1487+
first_row_id=2,
1488+
added_rows=10,
1489+
)
1490+
1491+
new_metadata = update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1492+
assert new_metadata.next_row_id == 11

0 commit comments

Comments
 (0)