Skip to content

Commit 3736bc1

Browse files
committed
resolve review comments
1 parent 8e833d2 commit 3736bc1

2 files changed

Lines changed: 40 additions & 41 deletions

File tree

src/iceberg/test/rewrite_manifests_test.cc

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

593603
TEST_P(RewriteManifestsTest, ReplaceManifestsSeparate) {

src/iceberg/update/rewrite_manifests.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,8 @@ Status RewriteManifests::Finalize(Result<const TableMetadata*> commit_result) {
238238

239239
bool RewriteManifests::RequiresRewrite(
240240
const std::unordered_set<std::string>& current_manifest_paths) const {
241-
const bool has_direct_replacements = !deleted_manifests_.empty() ||
242-
!added_manifests_.empty() ||
243-
!rewritten_added_manifests_.empty();
244-
if (!cluster_by_func_ && !predicate_ && has_direct_replacements) {
245-
// Manifests are deleted and added directly, so don't rewrite unrelated manifests
246-
// unless a clustering function or predicate explicitly requests it.
241+
if (!cluster_by_func_) {
242+
// manifests are deleted and added directly so don't perform a rewrite
247243
return false;
248244
}
249245
if (rewritten_manifests_.empty()) {
@@ -416,16 +412,9 @@ Result<std::vector<ManifestFile>> RewriteManifests::Rewrite(
416412

417413
auto new_writer = [this, &schema](const RewriteWriter& rewrite_writer)
418414
-> Result<std::unique_ptr<ManifestWriter>> {
419-
std::optional<int64_t> first_row_id = std::nullopt;
420-
if (base().format_version >= 3 && rewrite_writer.content == ManifestContent::kData) {
421-
// Rewritten manifests contain existing files only. Use a non-null manifest
422-
// first_row_id so v3 manifest-list writing does not assign new row IDs for
423-
// existing rows.
424-
first_row_id = 0;
425-
}
426415
return ManifestWriter::MakeWriter(base().format_version, SnapshotId(), ManifestPath(),
427416
ctx_->table->io(), rewrite_writer.spec, schema,
428-
rewrite_writer.content, first_row_id);
417+
rewrite_writer.content);
429418
};
430419

431420
std::vector<ManifestFile> result;

0 commit comments

Comments
 (0)