Skip to content

Conversation

@HeartLinked
Copy link
Contributor

No description provided.

Kind kind() const final { return Kind::kUpdateStatistics; }

struct ApplyResult {
std::unordered_map<int64_t, std::shared_ptr<StatisticsFile>> to_set;
Copy link
Member

Choose a reason for hiding this comment

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

Is it cheaper to use std::vector<std::pair<int64_t, std::shared_ptr<StatisticsFile>>>?

Comment on lines +47 to +49
const std::shared_ptr<StatisticsFile>& statistics_file) {
ICEBERG_BUILDER_CHECK(statistics_file != nullptr, "Statistics file cannot be null");
statistics_to_set_[statistics_file->snapshot_id] = statistics_file;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const std::shared_ptr<StatisticsFile>& statistics_file) {
ICEBERG_BUILDER_CHECK(statistics_file != nullptr, "Statistics file cannot be null");
statistics_to_set_[statistics_file->snapshot_id] = statistics_file;
std::shared_ptr<StatisticsFile> statistics_file) {
ICEBERG_BUILDER_CHECK(statistics_file != nullptr, "Statistics file cannot be null");
statistics_to_set_[statistics_file->snapshot_id] = std::move(statistics_file);

Comment on lines +191 to +194
// Apply statistics changes to the metadata builder
for (const auto& [snapshot_id, stat_file] : result.to_set) {
metadata_builder_->SetStatistics(stat_file);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Apply statistics changes to the metadata builder
for (const auto& [snapshot_id, stat_file] : result.to_set) {
metadata_builder_->SetStatistics(stat_file);
}
for (auto&& [_, stat_file] : result.to_set) {
metadata_builder_->SetStatistics(std::move(stat_file));
}

return false;
}
const auto& other_set = static_cast<const SetStatistics&>(other);
return *statistics_file_ == *other_set.statistics_file_;
Copy link
Member

Choose a reason for hiding this comment

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

nit: check null just in case.

}

void TableMetadataBuilder::Impl::SetLocation(std::string_view location) {
Status TableMetadataBuilder::Impl::SetLocation(std::string_view location) {
Copy link
Member

Choose a reason for hiding this comment

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

Why changing this? We don't need to return status if it never has any error.

}

Status TableMetadataBuilder::Impl::SetStatistics(
const std::shared_ptr<StatisticsFile>& statistics_file) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const std::shared_ptr<StatisticsFile>& statistics_file) {
std::shared_ptr<StatisticsFile> statistics_file) {


Status TableMetadataBuilder::Impl::SetStatistics(
const std::shared_ptr<StatisticsFile>& statistics_file) {
ICEBERG_CHECK(statistics_file != nullptr, "Cannot set null statistics file");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ICEBERG_CHECK(statistics_file != nullptr, "Cannot set null statistics file");
ICEBERG_PRECHECK(statistics_file != nullptr, "Cannot set null statistics file");

Note that PRECHECK returns InvalidArgument while CHECK returns ValidationFailed.

metadata_.statistics.push_back(statistics_file);
}

changes_.push_back(std::make_unique<table::SetStatistics>(statistics_file));
Copy link
Member

Choose a reason for hiding this comment

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

Use std::move

}

// Remove statistics for the given snapshot_id
std::erase_if(metadata_.statistics, [snapshot_id](const auto& stat) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we combine find and erase in a single call?

Copy link
Member

Choose a reason for hiding this comment

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

Or you can just call something like metadata_.statistics.erase(it) to avoid a 2nd iteration

json[kLocation] = u.location();
break;
}
case TableUpdate::Kind::kSetStatistics: {
Copy link
Member

Choose a reason for hiding this comment

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

Please also add FromJson equivalents and their test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants