in tfx_bsl/cc/sketches/misragries_sketch.cc [359:399]
absl::Status MisraGriesSketch::Merge(const MisraGriesSketch& other) {
if (other.num_buckets_ != num_buckets_) {
return absl::InvalidArgumentError(absl::StrCat(
"Both sketches must have the same number of buckets: ", num_buckets_,
" v.s. ", other.num_buckets_));
}
if (other.large_string_threshold_ != large_string_threshold_) {
return absl::InvalidArgumentError(
"Both sketches must have the same large_string_threshold.");
}
if (other.large_string_placeholder_ != large_string_placeholder_) {
return absl::InvalidArgumentError(
"Both sketches must have the same large_string_placeholder.");
}
if (other.invalid_utf8_placeholder_ != invalid_utf8_placeholder_) {
return absl::InvalidArgumentError(
"Both sketches must have the same invalid_utf8_placeholder.");
}
if (input_type_ == InputType::UNSET) {
input_type_ = other.input_type_;
}
if (other.input_type_ != InputType::UNSET &&
input_type_ != other.input_type_) {
return absl::InvalidArgumentError(
absl::StrFormat("Both sketches must have the same type (%s vs %s)",
InputType::Type_Name(input_type_),
InputType::Type_Name(other.input_type_)));
}
for (const auto& item : other.item_counts_) {
auto insertion_pair = item_counts_.insert(item);
if (!insertion_pair.second) {
insertion_pair.first->second += item.second;
}
}
for (const auto& item : other.extra_items_) {
extra_items_.insert(item);
}
delta_ += other.delta_;
Compress();
return absl::OkStatus();
}