|
| 1 | +// Copyright 2018 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +//! [all code] [START bigtable_quickstart] |
| 16 | + |
| 17 | +#include "google/cloud/bigtable/table.h" |
| 18 | + |
| 19 | +int main(int argc, char* argv[]) try { |
| 20 | + if (argc != 4) { |
| 21 | + std::string const cmd = argv[0]; |
| 22 | + auto last_slash = std::string(cmd).find_last_of('/'); |
| 23 | + std::cerr << "Usage: " << cmd.substr(last_slash + 1) |
| 24 | + << " <project_id> <instance_id> <table_id>" << std::endl; |
| 25 | + return 1; |
| 26 | + } |
| 27 | + |
| 28 | + std::string const project_id = argv[1]; |
| 29 | + std::string const instance_id = argv[2]; |
| 30 | + std::string const table_id = argv[3]; |
| 31 | + |
| 32 | + google::cloud::bigtable::Table table( |
| 33 | + google::cloud::bigtable::CreateDefaultDataClient( |
| 34 | + project_id, instance_id, google::cloud::bigtable::ClientOptions()), |
| 35 | + table_id); |
| 36 | + |
| 37 | + std::string row_key = "r1"; |
| 38 | + std::string column_family = "cf1"; |
| 39 | + |
| 40 | + std::cout << "Getting a single row by row key:" << std::flush; |
| 41 | + auto result = table.ReadRow( |
| 42 | + row_key, google::cloud::bigtable::Filter::FamilyRegex(column_family)); |
| 43 | + if (not result.first) { |
| 44 | + std::cout << "Cannot find row " << row_key << " in the table: " << table_id |
| 45 | + << std::endl; |
| 46 | + return 0; |
| 47 | + } |
| 48 | + |
| 49 | + auto const& cell = result.second.cells().front(); |
| 50 | + std::cout << cell.family_name() << ":" << cell.column_qualifier() << " @ " |
| 51 | + << cell.timestamp().count() << "us\n" |
| 52 | + << '"' << cell.value() << '"' << std::endl; |
| 53 | + |
| 54 | + return 0; |
| 55 | +} catch (std::exception const& ex) { |
| 56 | + std::cerr << "Standard C++ exception raised: " << ex.what() << std::endl; |
| 57 | + return 1; |
| 58 | +} |
| 59 | +//! [all code] [END bigtable_quickstart] |
0 commit comments