Skip to content

Commit 38c1afe

Browse files
committed
add tests
1 parent 6da3977 commit 38c1afe

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

tests/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
from pyiceberg.schema import Accessor, Schema
6565
from pyiceberg.serializers import ToOutputFile
6666
from pyiceberg.table import FileScanTask, Table
67-
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2
67+
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2, TableMetadataV3
6868
from pyiceberg.types import (
6969
BinaryType,
7070
BooleanType,
@@ -906,6 +906,7 @@ def generate_snapshot(
906906
"table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
907907
"location": "s3://bucket/test/location",
908908
"last-sequence-number": 34,
909+
"next-row-id": 1,
909910
"last-updated-ms": 1602638573590,
910911
"last-column-id": 3,
911912
"current-schema-id": 1,
@@ -2342,6 +2343,18 @@ def table_v2(example_table_metadata_v2: Dict[str, Any]) -> Table:
23422343
)
23432344

23442345

2346+
@pytest.fixture
2347+
def table_v3(example_table_metadata_v3: Dict[str, Any]) -> Table:
2348+
table_metadata = TableMetadataV3(**example_table_metadata_v3)
2349+
return Table(
2350+
identifier=("database", "table"),
2351+
metadata=table_metadata,
2352+
metadata_location=f"{table_metadata.location}/uuid.metadata.json",
2353+
io=load_file_io(),
2354+
catalog=NoopCatalog("NoopCatalog"),
2355+
)
2356+
2357+
23452358
@pytest.fixture
23462359
def table_v2_with_fixed_and_decimal_types(
23472360
table_metadata_v2_with_fixed_and_decimal_types: Dict[str, Any],

tests/table/test_init.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,3 +1345,57 @@ def test_remove_statistics_update(table_v2_with_statistics: Table) -> None:
13451345
table_v2_with_statistics.metadata,
13461346
(RemoveStatisticsUpdate(snapshot_id=123456789),),
13471347
)
1348+
1349+
1350+
def test_add_snapshot_update_fails_without_first_row_id(table_v3: Table) -> None:
1351+
new_snapshot = Snapshot(
1352+
snapshot_id=25,
1353+
parent_snapshot_id=19,
1354+
sequence_number=200,
1355+
timestamp_ms=1602638593590,
1356+
manifest_list="s3:/a/b/c.avro",
1357+
summary=Summary(Operation.APPEND),
1358+
schema_id=3,
1359+
)
1360+
1361+
with pytest.raises(
1362+
ValueError,
1363+
match="Cannot add snapshot without first row id",
1364+
):
1365+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1366+
1367+
1368+
def test_add_snapshot_update_fails_with_smaller_first_row_id(table_v3: Table) -> None:
1369+
new_snapshot = Snapshot(
1370+
snapshot_id=25,
1371+
parent_snapshot_id=19,
1372+
sequence_number=200,
1373+
timestamp_ms=1602638593590,
1374+
manifest_list="s3:/a/b/c.avro",
1375+
summary=Summary(Operation.APPEND),
1376+
schema_id=3,
1377+
first_row_id=0,
1378+
)
1379+
1380+
with pytest.raises(
1381+
ValueError,
1382+
match="Cannot add a snapshot with first row id smaller than the table's next-row-id",
1383+
):
1384+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1385+
1386+
1387+
def test_add_snapshot_update_updates_next_row_id(table_v3: Table) -> None:
1388+
new_snapshot = Snapshot(
1389+
snapshot_id=25,
1390+
parent_snapshot_id=19,
1391+
sequence_number=200,
1392+
timestamp_ms=1602638593590,
1393+
manifest_list="s3:/a/b/c.avro",
1394+
summary=Summary(Operation.APPEND),
1395+
schema_id=3,
1396+
first_row_id=2,
1397+
added_rows=10,
1398+
)
1399+
1400+
new_metadata = update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1401+
assert new_metadata.next_row_id == 11

0 commit comments

Comments
 (0)