@@ -549,45 +549,55 @@ TEST_P(RewriteManifestsTest, RewriteManifestsWithoutClusterBy) {
549549
550550 ICEBERG_UNWRAP_OR_FAIL (auto manifests, CurrentManifests ());
551551 ASSERT_EQ (manifests.size (), 1U );
552- EXPECT_NE (manifests[0 ].manifest_path , before[0 ].manifest_path );
552+ EXPECT_EQ (manifests[0 ].manifest_path , before[0 ].manifest_path );
553553 ExpectManifestEntriesWithSnapshotIds (manifests[0 ], {file_a_->file_path },
554- {ManifestStatus::kExisting }, {append_id});
554+ {ManifestStatus::kAdded }, {append_id});
555555}
556556
557- TEST_P (RewriteManifestsTest, RewriteIfWithoutClusterBy) {
557+ TEST_P (RewriteManifestsTest, RewriteAfterV2ToV3UpgradeAssignsRowIds) {
558+ if (format_version () != 2 ) {
559+ GTEST_SKIP () << " This regression starts from a v2 table" ;
560+ }
561+
558562 ASSERT_THAT (AppendFiles ({file_a_}), IsOk ());
559- ICEBERG_UNWRAP_OR_FAIL (auto append_snapshot_a, table_->current_snapshot ());
560- const int64_t append_id_a = append_snapshot_a->snapshot_id ;
561563 ASSERT_THAT (AppendFiles ({file_b_}), IsOk ());
562- ICEBERG_UNWRAP_OR_FAIL (auto append_snapshot_b, table_->current_snapshot ());
563- const int64_t append_id_b = append_snapshot_b->snapshot_id ;
564- ASSERT_THAT (AppendFiles ({file_c_}), IsOk ());
565- ICEBERG_UNWRAP_OR_FAIL (auto append_snapshot_c, table_->current_snapshot ());
566- const int64_t append_id_c = append_snapshot_c->snapshot_id ;
564+
565+ ICEBERG_UNWRAP_OR_FAIL (auto original_manifests, CurrentManifests ());
566+ ASSERT_EQ (original_manifests.size (), 2U );
567+ for (const auto & manifest : original_manifests) {
568+ EXPECT_FALSE (manifest.first_row_id .has_value ());
569+ }
570+
571+ ICEBERG_UNWRAP_OR_FAIL (auto props, table_->NewUpdateProperties ());
572+ props->Set (std::string (TableProperties::kFormatVersion .key ()), " 3" );
573+ EXPECT_THAT (props->Commit (), IsOk ());
574+ EXPECT_THAT (table_->Refresh (), IsOk ());
575+ EXPECT_EQ (table_->metadata ()->format_version , 3 );
576+ EXPECT_EQ (table_->metadata ()->next_row_id , TableMetadata::kInitialRowId );
567577
568578 ICEBERG_UNWRAP_OR_FAIL (auto rewrite, table_->NewRewriteManifests ());
569- rewrite->RewriteIf ([&](const ManifestFile& manifest) {
570- auto entries_result = ReadManifestEntries (manifest);
571- if (!entries_result.has_value () || entries_result.value ().empty ()) {
572- return false ;
573- }
574- return entries_result.value ()[0 ].data_file ->file_path != file_a_->file_path ;
575- });
579+ rewrite->ClusterBy ([](const DataFile&) { return " " ; });
576580 EXPECT_THAT (rewrite->Commit (), IsOk ());
577581
578582 ICEBERG_UNWRAP_OR_FAIL (auto manifests, CurrentManifests ());
579- ASSERT_EQ (manifests.size (), 2U );
583+ ASSERT_EQ (manifests.size (), 1U );
584+ EXPECT_EQ (manifests[0 ].first_row_id ,
585+ std::make_optional<int64_t >(TableMetadata::kInitialRowId ));
580586
581- ICEBERG_UNWRAP_OR_FAIL (auto kept_manifest,
582- ManifestContainingPath (manifests, file_a_->file_path ));
583- ICEBERG_UNWRAP_OR_FAIL (auto rewritten_manifest,
584- ManifestContainingPath (manifests, file_b_->file_path ));
587+ ICEBERG_UNWRAP_OR_FAIL (auto entries, ReadManifestEntries (manifests[0 ]));
588+ ASSERT_EQ (entries.size (), 2U );
585589
586- ExpectManifestEntriesWithSnapshotIds (*kept_manifest, {file_a_->file_path },
587- {ManifestStatus::kAdded }, {append_id_a});
588- ExpectManifestEntriesWithSnapshotIds (
589- *rewritten_manifest, {file_b_->file_path , file_c_->file_path },
590- {ManifestStatus::kExisting , ManifestStatus::kExisting }, {append_id_b, append_id_c});
590+ int64_t next_row_id = TableMetadata::kInitialRowId ;
591+ int64_t assigned_rows = 0 ;
592+ for (const auto & entry : entries) {
593+ ASSERT_NE (entry.data_file , nullptr );
594+ ASSERT_TRUE (entry.data_file ->first_row_id .has_value ());
595+ EXPECT_EQ (entry.data_file ->first_row_id .value (), next_row_id);
596+ next_row_id += entry.data_file ->record_count ;
597+ assigned_rows += entry.data_file ->record_count ;
598+ }
599+ EXPECT_EQ (table_->metadata ()->next_row_id ,
600+ TableMetadata::kInitialRowId + assigned_rows);
591601}
592602
593603TEST_P (RewriteManifestsTest, ReplaceManifestsSeparate) {
0 commit comments