in src/hbase/client/scan-result-cache.cc [82:121]
std::shared_ptr<Result> ScanResultCache::CreateCompleteResult(
const std::vector<std::shared_ptr<Result>> &partial_results) {
if (partial_results.empty()) {
return std::make_shared<Result>(std::vector<std::shared_ptr<Cell>>{}, false, false, false);
}
std::vector<std::shared_ptr<Cell>> cells{};
bool stale = false;
std::string prev_row = "";
std::string current_row = "";
size_t i = 0;
for (const auto &r : partial_results) {
current_row = r->Row();
if (i != 0 && prev_row != current_row) {
throw new std::runtime_error(
"Cannot form complete result. Rows of partial results do not match.");
}
// Ensure that all Results except the last one are marked as partials. The last result
// may not be marked as a partial because Results are only marked as partials when
// the scan on the server side must be stopped due to reaching the maxResultSize.
// Visualizing it makes it easier to understand:
// maxResultSize: 2 cells
// (-x-) represents cell number x in a row
// Example: row1: -1- -2- -3- -4- -5- (5 cells total)
// How row1 will be returned by the server as partial Results:
// Result1: -1- -2- (2 cells, size limit reached, mark as partial)
// Result2: -3- -4- (2 cells, size limit reached, mark as partial)
// Result3: -5- (1 cell, size limit NOT reached, NOT marked as partial)
if (i != partial_results.size() - 1 && !r->Partial()) {
throw new std::runtime_error("Cannot form complete result. Result is missing partial flag.");
}
prev_row = current_row;
stale = stale || r->Stale();
for (const auto &c : r->Cells()) {
cells.push_back(c);
}
i++;
}
return std::make_shared<Result>(cells, false, stale, false);
}