@@ -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