Google Cloud Platform Bigtable C++ Client Library
Cloud Bigtable is Google's NoSQL Big Data database service. It's the same database that powers many core Google services, including Search, Analytics, Maps, and Gmail.
The Cloud Bigtable C++ Client library offers types and functions to access Cloud Bigtable from C++ applications. It offers access to the Cloud Bigtable API, including admin operations to list, read, write, and delete Instances, Clusters, Tables, and Application Profiles.
Quickstart
The following "Hello World" program should give you a sense of how to use the library.
#include "google/cloud/bigtable/table.h"
int main(int argc, char* argv[]) try {
if (argc != 4) {
std::string const cmd = argv[0];
auto last_slash = std::string(cmd).find_last_of('/');
std::cerr << "Usage: " << cmd.substr(last_slash + 1)
<< " <project_id> <instance_id> <table_id>\n";
return 1;
}
std::string const project_id = argv[1];
std::string const instance_id = argv[2];
std::string const table_id = argv[3];
// Create a namespace alias to make the code easier to read.
namespace cbt = ::google::cloud::bigtable;
cbt::Table table(cbt::MakeDataConnection(),
cbt::TableResource(project_id, instance_id, table_id));
std::string row_key = "r1";
std::string column_family = "cf1";
std::cout << "Getting a single row by row key:" << std::flush;
google::cloud::StatusOr<std::pair<bool, cbt::Row>> result =
table.ReadRow(row_key, cbt::Filter::FamilyRegex(column_family));
if (!result) throw std::move(result).status();
if (!result->first) {
std::cout << "Cannot find row " << row_key << " in the table: " << table_id
<< "\n";
return 0;
}
cbt::Cell const& cell = result->second.cells().front();
std::cout << cell.family_name() << ":" << cell.column_qualifier() << " @ "
<< cell.timestamp().count() << "us\n"
<< '"' << cell.value() << '"' << "\n";
return 0;
} catch (google::cloud::Status const& status) {
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return 1;
}
More Information
- Read more about Cloud Bigtable
Table::ReadRow()
- to read a single row from an existing TableTable::ReadRows()
- to read multiple rows from an existing TableTable::Apply()
- to update or insert new rows into a TableTable::BulkApply()
- to update or insert multiple rows into a Table- Getting Started with Bigtable
- Advanced Reading and Writing Samples
- Getting Started with Bigtable Table Administrative Operations
- Getting Started with Bigtable Instance Administrative Operations
- Error Handling to learn how the library reports run-time errors.
- Environment Variables for environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.
- Override the default endpoint
- Override the authentication configuration
- Override Retry, Backoff, and Idempotency Policies
- Mocking the Cloud Bigtable C++ client
- The Setting up your development environment guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries.