-
Notifications
You must be signed in to change notification settings - Fork 80
feat: implement update stastics #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Kind kind() const final { return Kind::kUpdateStatistics; } | ||
|
|
||
| struct ApplyResult { | ||
| std::unordered_map<int64_t, std::shared_ptr<StatisticsFile>> to_set; |
There was a problem hiding this comment.
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>>>?
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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); |
| // Apply statistics changes to the metadata builder | ||
| for (const auto& [snapshot_id, stat_file] : result.to_set) { | ||
| metadata_builder_->SetStatistics(stat_file); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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_; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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)); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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.
No description provided.