Google Cloud Bigtable C++ Client  1.15.0
A C++ Client Library for Google Cloud Bigtable
Google Cloud Platform Bigtable C++ Client Library

Overview

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++11 applications (Read more about Cloud Bigtable). It offers access to the Cloud Bigtable API, including operations to list, read, write, and delete Instances and Clusters, Tables and Application Profiles.

Quickstart

The following instructions show you how to perform basic tasks in Cloud Bigtable using the C++ client library.

Before you begin

  1. Select or create a Google Cloud Platform (GCP) project using the manage resource page. Make a note of the project id, you will need to use it later.
  2. Make sure that billing is enabled for your project.
  3. Learn about key terms and concepts for Cloud Spanner.
  4. Setup the authentication for the examples:

Setting up your repo

In order to use the Cloud Bigtable C++ client library from your own code, you'll need to configure your build system how to fetch and compile the Cloud C++ client library. The Cloud C++ client library natively supports the Bazel and CMake build systems. We've created a minimal, "Hello world", [quickstart repo][quickstart-link] that includes detailed instructions on how to compile the library for use in your application. You can fetch the source from GitHub as normal:

git clone https://github.com/googleapis/google-cloud-cpp.git
cd google-cloud-cpp/google/cloud/bigtable/quickstart
Example: Quickstart

The following shows the code that you'll run in the google/cloud/bigtable/quickstart/ directory, which should give you a taste of the Cloud Bigtable C++ client library API.

// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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.
cbt::Table table(cbt::CreateDefaultDataClient(project_id, instance_id,
cbt::ClientOptions()),
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::runtime_error(result.status().message());
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 (std::exception const& ex) {
std::cerr << "Standard C++ exception raised: " << ex.what() << "\n";
return 1;
}

API Notes

  • GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes turns on logging in the library, basically the library always "logs" but the logging infrastructure has no backend to actually print anything until the application sets a backend or they set this environment variable.
  • GOOGLE_CLOUD_PROJECT=... is used in examples and integration tests to configure the GCP project.
  • BIGTABLE_EMULATOR_HOST=host:port tells the library to connect to the specified emulator rather than the default endpoint.

Next Steps