Skip to content

Commit 54ef773

Browse files
committed
add tests
1 parent 130a96a commit 54ef773

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

tests/conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
from pyiceberg.schema import Accessor, Schema
7373
from pyiceberg.serializers import ToOutputFile
7474
from pyiceberg.table import FileScanTask, Table
75-
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2
75+
from pyiceberg.table.metadata import TableMetadataV1, TableMetadataV2, TableMetadataV3
7676
from pyiceberg.transforms import DayTransform, IdentityTransform
7777
from pyiceberg.types import (
7878
BinaryType,
@@ -920,6 +920,7 @@ def generate_snapshot(
920920
"table-uuid": "9c12d441-03fe-4693-9a96-a0705ddf69c1",
921921
"location": "s3://bucket/test/location",
922922
"last-sequence-number": 34,
923+
"next-row-id": 1,
923924
"last-updated-ms": 1602638573590,
924925
"last-column-id": 3,
925926
"current-schema-id": 1,
@@ -2489,6 +2490,18 @@ def table_v2(example_table_metadata_v2: Dict[str, Any]) -> Table:
24892490
)
24902491

24912492

2493+
@pytest.fixture
2494+
def table_v3(example_table_metadata_v3: Dict[str, Any]) -> Table:
2495+
table_metadata = TableMetadataV3(**example_table_metadata_v3)
2496+
return Table(
2497+
identifier=("database", "table"),
2498+
metadata=table_metadata,
2499+
metadata_location=f"{table_metadata.location}/uuid.metadata.json",
2500+
io=load_file_io(),
2501+
catalog=NoopCatalog("NoopCatalog"),
2502+
)
2503+
2504+
24922505
@pytest.fixture
24932506
def table_v2_orc(example_table_metadata_v2: Dict[str, Any]) -> Table:
24942507
import copy

tests/table/test_init.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,3 +1521,56 @@ def test_remove_partition_statistics_update_with_invalid_snapshot_id(table_v2_wi
15211521
table_v2_with_statistics.metadata,
15221522
(RemovePartitionStatisticsUpdate(snapshot_id=123456789),),
15231523
)
1524+
1525+
def test_add_snapshot_update_fails_without_first_row_id(table_v3: Table) -> None:
1526+
new_snapshot = Snapshot(
1527+
snapshot_id=25,
1528+
parent_snapshot_id=19,
1529+
sequence_number=200,
1530+
timestamp_ms=1602638593590,
1531+
manifest_list="s3:/a/b/c.avro",
1532+
summary=Summary(Operation.APPEND),
1533+
schema_id=3,
1534+
)
1535+
1536+
with pytest.raises(
1537+
ValueError,
1538+
match="Cannot add snapshot without first row id",
1539+
):
1540+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1541+
1542+
1543+
def test_add_snapshot_update_fails_with_smaller_first_row_id(table_v3: Table) -> None:
1544+
new_snapshot = Snapshot(
1545+
snapshot_id=25,
1546+
parent_snapshot_id=19,
1547+
sequence_number=200,
1548+
timestamp_ms=1602638593590,
1549+
manifest_list="s3:/a/b/c.avro",
1550+
summary=Summary(Operation.APPEND),
1551+
schema_id=3,
1552+
first_row_id=0,
1553+
)
1554+
1555+
with pytest.raises(
1556+
ValueError,
1557+
match="Cannot add a snapshot with first row id smaller than the table's next-row-id",
1558+
):
1559+
update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1560+
1561+
1562+
def test_add_snapshot_update_updates_next_row_id(table_v3: Table) -> None:
1563+
new_snapshot = Snapshot(
1564+
snapshot_id=25,
1565+
parent_snapshot_id=19,
1566+
sequence_number=200,
1567+
timestamp_ms=1602638593590,
1568+
manifest_list="s3:/a/b/c.avro",
1569+
summary=Summary(Operation.APPEND),
1570+
schema_id=3,
1571+
first_row_id=2,
1572+
added_rows=10,
1573+
)
1574+
1575+
new_metadata = update_table_metadata(table_v3.metadata, (AddSnapshotUpdate(snapshot=new_snapshot),))
1576+
assert new_metadata.next_row_id == 11

0 commit comments

Comments
 (0)