Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/iceberg/test/merging_snapshot_update_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>

#include <gmock/gmock.h>
Expand All @@ -37,6 +38,8 @@
#include "iceberg/manifest/manifest_entry.h"
#include "iceberg/manifest/manifest_reader.h"
#include "iceberg/manifest/manifest_writer.h"
#include "iceberg/metrics/commit_report.h"
#include "iceberg/metrics/metrics_reporter.h"
#include "iceberg/partition_spec.h"
#include "iceberg/puffin_dv_io.h"
#include "iceberg/row/partition_values.h"
Expand All @@ -59,6 +62,20 @@

namespace iceberg {

namespace {

class MergingSnapshotCapturingReporter final : public MetricsReporter {
public:
Status Report(const MetricsReport& report) override {
reports.push_back(report);
return {};
}

std::vector<MetricsReport> reports;
};

} // namespace

class RecordingPuffinDVIO final : public PuffinDVIO {
public:
struct Call {
Expand Down Expand Up @@ -564,6 +581,29 @@ TEST_F(MergingSnapshotUpdateTest, CommitNewDataFile) {
EXPECT_EQ(snapshot->summary.at(SnapshotSummaryFields::kAddedRecords), "100");
}

TEST_F(MergingSnapshotUpdateTest, CommitReportsCreatedSnapshot) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for this test case.

auto reporter = std::make_shared<MergingSnapshotCapturingReporter>();
ICEBERG_UNWRAP_OR_FAIL(auto op, NewMergeAppend());
op->ReportWith(reporter);
EXPECT_THAT(op->AddFile(file_a_), IsOk());
EXPECT_THAT(op->Commit(), IsOk());

ASSERT_EQ(reporter->reports.size(), 1U);
ASSERT_TRUE(std::holds_alternative<CommitReport>(reporter->reports.front()));
const auto& report = std::get<CommitReport>(reporter->reports.front());

EXPECT_THAT(table_->Refresh(), IsOk());
ICEBERG_UNWRAP_OR_FAIL(auto snapshot, table_->current_snapshot());
EXPECT_EQ(report.table_name, table_->full_name());
EXPECT_EQ(report.operation, DataOperation::kAppend);
EXPECT_EQ(report.snapshot_id, snapshot->snapshot_id);
EXPECT_EQ(report.sequence_number, snapshot->sequence_number);
ASSERT_TRUE(report.commit_metrics.added_data_files.has_value());
EXPECT_EQ(report.commit_metrics.added_data_files->value, 1);
ASSERT_TRUE(report.commit_metrics.added_records.has_value());
EXPECT_EQ(report.commit_metrics.added_records->value, 100);
}

TEST_F(MergingSnapshotUpdateTest, CommitV3NewDataFileAssignsRowLineage) {
UpgradeTableToV3();

Expand Down
6 changes: 0 additions & 6 deletions src/iceberg/update/merging_snapshot_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ namespace iceberg {
/// 5. Write new delete manifests (cached for commit retry)
/// 6. Merge data manifests (via data_merge_manager_)
/// 7. Merge delete manifests (via delete_merge_manager_)
///
/// TODO(Guotao): Java MergingSnapshotProducer overrides updateEvent() to return a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MetricsReporter covers the commit reporting use case, but it is not exactly the same as Java's event listener mechanism. Java handles event notification and metrics reporting separately. If we don't plan to support a general event listener in C++, removing this TODO is fine.

/// CreateSnapshotEvent(tableName, operation, snapshotId, sequenceNumber, summary)
/// for commit listeners. The C++ update framework does not yet have an event
/// notification mechanism, so this is intentionally not implemented here. Add it
/// once an equivalent CreateSnapshotEvent / listener facility exists.
class ICEBERG_EXPORT MergingSnapshotUpdate : public SnapshotUpdate {
public:
~MergingSnapshotUpdate() override = default;
Expand Down
Loading