| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c2c07ed commit 75bd122
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,7 +159,7 @@ void Table::SampleRowsImpl(std::function<void(Table::RowKeySample)> inserter, | |||
| 159 | 159 | // Assuming collection will be either list or vector. | |
| 160 | 160 | Table::RowKeySample row_sample; | |
| 161 | 161 | row_sample.offset_bytes = response.offset_bytes(); | |
| 162 | - row_sample.row_key = std::move(response.row_key()); | ||
| 162 | + row_sample.row_key = std::move(*response.mutable_row_key()); | ||
| 163 | 163 | inserter(std::move(row_sample)); | |
| 164 | 164 | } | |
| 165 | 165 | auto status = stream->Finish(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -365,3 +365,51 @@ TEST_F(DataIntegrationTest, TableReadModifyWriteRowMultipleTest) { | |||
| 365 | 365 | DeleteTable(table_name); | |
| 366 | 366 | CheckEqualUnordered(expected_ignore_timestamp, actual_ignore_timestamp); | |
| 367 | 367 | } | |
| 368 | + | ||
| 369 | + TEST_F(DataIntegrationTest, TableSampleRowKeysTest) { | ||
| 370 | + std::string const table_name = "table-sample-row-keys-test"; | ||
| 371 | + auto table = CreateTable(table_name, table_config); | ||
| 372 | + | ||
| 373 | + // Create BATCH_SIZE * BATCH_COUNT rows. | ||
| 374 | + constexpr int BATCH_COUNT = 10; | ||
| 375 | + constexpr int BATCH_SIZE = 5000; | ||
| 376 | + constexpr int COLUMN_COUNT = 10; | ||
| 377 | + int rowid = 0; | ||
| 378 | + for (int batch = 0; batch != BATCH_COUNT; ++batch) { | ||
| 379 | + bigtable::BulkMutation bulk; | ||
| 380 | + for (int row = 0; row != BATCH_SIZE; ++row) { | ||
| 381 | + std::ostringstream os; | ||
| 382 | + os << "row:" << std::setw(9) << std::setfill('0') << rowid; | ||
| 383 | + | ||
| 384 | + // Build a mutation that creates 10 columns. | ||
| 385 | + bigtable::SingleRowMutation mutation(os.str()); | ||
| 386 | + for (int col = 0; col != COLUMN_COUNT; ++col) { | ||
| 387 | + std::string colid = "c" + std::to_string(col); | ||
| 388 | + std::string value = colid + "#" + os.str(); | ||
| 389 | + mutation.emplace_back( | ||
| 390 | + bigtable::SetCell(family1, std::move(colid), std::move(value))); | ||
| 391 | + } | ||
| 392 | + bulk.emplace_back(std::move(mutation)); | ||
| 393 | + ++rowid; | ||
| 394 | + } | ||
| 395 | + table->BulkApply(std::move(bulk)); | ||
| 396 | + } | ||
| 397 | + auto samples = table->SampleRows<std::vector>(); | ||
| 398 | + DeleteTable(table_name); | ||
| 399 | + | ||
| 400 | + // It is somewhat hard to verify that the values returned here are correct. | ||
| 401 | + // We cannot check the specific values, not even the format, of the row keys | ||
| 402 | + // because Cloud Bigtable might return an empty row key (for "end of table"), | ||
| 403 | + // and it might return row keys that have never been written to. | ||
| 404 | + // All we can check is that this is not empty, and that the offsets are in | ||
| 405 | + // ascending order. | ||
| 406 | + EXPECT_FALSE(samples.empty()); | ||
| 407 | + std::int64_t previous = 0; | ||
| 408 | + for (auto const& s : samples) { | ||
| 409 | + EXPECT_LE(previous, s.offset_bytes); | ||
| 410 | + previous = s.offset_bytes; | ||
| 411 | + } | ||
| 412 | + // At least one of the samples should have non-zero offset: | ||
| 413 | + auto last = samples.back(); | ||
| 414 | + EXPECT_LT(0, last.offset_bytes); | ||
| 415 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments