Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
google::cloud::bigtable::Table Class Reference

The main interface to interact with data in a Cloud Bigtable table. More...

#include <google/cloud/bigtable/table.h>

Public Member Functions

 Table (std::shared_ptr< bigtable::DataConnection > conn, TableResource tr, Options options={})
 Constructs a Table object. More...
 
std::string const & table_name () const
 
std::string const & app_profile_id () const
 
std::string const & project_id () const
 
std::string const & instance_id () const
 
std::string const & table_id () const
 
Table WithNewTarget (std::string project_id, std::string instance_id, std::string table_id) const
 Returns a Table that reuses the connection and configuration of this Table, but with a different resource name. More...
 
Table WithNewTarget (std::string project_id, std::string instance_id, std::string app_profile_id, std::string table_id) const
 Returns a Table that reuses the connection and configuration of this Table, but with a different resource name. More...
 
Status Apply (SingleRowMutation mut, Options opts={})
 Attempts to apply the mutation to a row. More...
 
future< StatusAsyncApply (SingleRowMutation mut, Options opts={})
 Makes asynchronous attempts to apply the mutation to a row. More...
 
std::vector< FailedMutationBulkApply (BulkMutation mut, Options opts={})
 Attempts to apply mutations to multiple rows. More...
 
future< std::vector< FailedMutation > > AsyncBulkApply (BulkMutation mut, Options opts={})
 Makes asynchronous attempts to apply mutations to multiple rows. More...
 
RowReader ReadRows (RowSet row_set, Filter filter, Options opts={})
 Reads a set of rows from the table. More...
 
RowReader ReadRows (RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
 Reads a limited set of rows from the table. More...
 
StatusOr< std::pair< bool, Row > > ReadRow (std::string row_key, Filter filter, Options opts={})
 Read and return a single row from the table. More...
 
StatusOr< MutationBranchCheckAndMutateRow (std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
 Atomic test-and-set for a row using filter expressions. More...
 
future< StatusOr< MutationBranch > > AsyncCheckAndMutateRow (std::string row_key, Filter filter, std::vector< Mutation > true_mutations, std::vector< Mutation > false_mutations, Options opts={})
 Make an asynchronous request to conditionally mutate a row. More...
 
StatusOr< std::vector< bigtable::RowKeySample > > SampleRows (Options opts={})
 Sample of the row keys in the table, including approximate data sizes. More...
 
future< StatusOr< std::vector< bigtable::RowKeySample > > > AsyncSampleRows (Options opts={})
 Asynchronously obtains a sample of the row keys in the table, including approximate data sizes. More...
 
template<typename... Args>
StatusOr< RowReadModifyWriteRow (std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
 Atomically read and modify the row in the server, returning the resulting row. More...
 
template<typename... Args>
future< StatusOr< Row > > AsyncReadModifyWriteRow (std::string row_key, bigtable::ReadModifyWriteRule rule, Args &&... rules_and_options)
 Make an asynchronous request to atomically read and modify a row. More...
 
template<typename RowFunctor , typename FinishFunctor >
void AsyncReadRows (RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, Filter filter, Options opts={})
 Asynchronously reads a set of rows from the table. More...
 
template<typename RowFunctor , typename FinishFunctor >
void AsyncReadRows (RowFunctor on_row, FinishFunctor on_finish, RowSet row_set, std::int64_t rows_limit, Filter filter, Options opts={})
 Asynchronously reads a set of rows from the table. More...
 
future< StatusOr< std::pair< bool, Row > > > AsyncReadRow (std::string row_key, Filter filter, Options opts={})
 Asynchronously read and return a single row from the table. More...
 
 Table (std::shared_ptr< DataClient > client, std::string const &table_id)
 Constructor with default policies. More...
 
 Table (std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id)
 Constructor with default policies. More...
 
template<typename... Policies>
 Table (std::shared_ptr< DataClient > client, std::string const &table_id, Policies &&... policies)
 Constructor with explicit policies. More...
 
template<typename... Policies>
 Table (std::shared_ptr< DataClient > client, std::string app_profile_id, std::string const &table_id, Policies &&... policies)
 Constructor with explicit policies. More...
 

Friends

class MutationBatcher
 

Detailed Description

The main interface to interact with data in a Cloud Bigtable table.

This class provides member functions to:

The class deals with the most common transient failures, and retries the underlying RPC calls subject to the policies configured by the application. These policies are documented in Table::Table().

Thread-safety
Instances of this class created via copy-construction or copy-assignment share the underlying pool of connections. Access to these copies via multiple threads is guaranteed to work. Two threads operating concurrently on the same instance of this class is not guaranteed to work.
Cost
Creating a new object of type Table is comparable to creating a few objects of type std::string or a few objects of type std::shared_ptr<int>. The class represents a shallow handle to a remote object.
Error Handling
This class uses StatusOr<T> to report errors. When an operation fails to perform its work the returned StatusOr<T> contains the error details. If the ok() member function in the StatusOr<T> returns true then it contains the expected result. Operations that do not return a value simply return a google::cloud::Status indicating success or the details of the error Please consult the `StatusOr<T>` documentation for more details.
namespace cbt = google::cloud::bigtable;
cbt::Table = ...;
if (!row) {
std::cerr << "Error reading row\n";
return;
}
// Use "row" as a smart pointer here, e.g.:
if (!row->first) {
std::cout << "Contacting the server was successful, but the row does not"
<< " exist\n";
return;
}
std::cout << "The row has " << row->second.cells().size() << " cells\n";
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28

In addition, the main page contains examples using StatusOr<T> to handle errors.

Retry, Backoff, and Idempotency Policies
The library automatically retries requests that fail with transient errors, and uses truncated exponential backoff to backoff between retries. The default policies are to continue retrying for up to 10 minutes. On each transient failure the backoff period is doubled, starting with an initial backoff of 100 milliseconds. The backoff period growth is truncated at 60 seconds. The default idempotency policy is to only retry idempotent operations. Note that most operations that change state are not idempotent.

The application can override these policies when constructing objects of this class. The documentation for the constructors show examples of this in action.

See also
https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
https://cloud.google.com/bigtable/docs/overview for an overview of the Cloud Bigtable data model.
https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an introduction of the main APIs into Cloud Bigtable.
https://cloud.google.com/bigtable/docs/reference/service-apis-overview for an overview of the underlying Cloud Bigtable API.
google::cloud::StatusOr for a description of the error reporting class used by this library.
LimitedTimeRetryPolicy and LimitedErrorCountRetryPolicy for alternative retry policies.
ExponentialBackoffPolicy to configure different parameters for the exponential backoff policy.
SafeIdempotentMutationPolicy and AlwaysRetryMutationPolicy for alternative idempotency policies.

Constructor & Destructor Documentation

◆ Table() [1/5]

google::cloud::bigtable::Table::Table ( std::shared_ptr< bigtable::DataConnection conn,
TableResource  tr,
Options  options = {} 
)
inlineexplicit

Constructs a Table object.

Parameters
connthe connection to the Cloud Bigtable service. See MakeDataConnection() for how to create a connection. To mock the behavior of Table in your tests, use a bigtable_mocks::MockDataConnection.
tridentifies the table resource by its project, instance, and table ids.
optionsConfiguration options for the table. Use AppProfileIdOption to supply an app profile for the Table operations. Or configure retry / backoff / idempotency policies with the options enumerated in DataPolicyOptionList.
Example Using AppProfile
auto options =
google::cloud::Options{}.set<cbt::AppProfileIdOption>(profile_id);
cbt::Table read(connection,
cbt::TableResource(project_id, instance_id, table_id),
options);
read.ReadRow("key-0", cbt::Filter::ColumnRangeClosed("fam", "c0", "c0"));
if (!result) throw std::move(result).status();
if (!result->first) throw std::runtime_error("missing row with key = key-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";
Options & set(ValueTypeT< T > v)
Status const & status() const &
std::string const & project_id() const
Definition: table.h:220
std::string const & instance_id() const
Definition: table.h:223
std::string const & table_id() const
Definition: table.h:226
Idempotency Policy Example
using ::google::cloud::Options;
namespace cbt = ::google::cloud::bigtable;
[](std::string const& project_id, std::string const& instance_id,
std::string const& table_id, std::string const& row_key) {
cbt::Table table(cbt::MakeDataConnection(),
cbt::TableResource(project_id, instance_id, table_id),
Options{}.set<cbt::IdempotentMutationPolicyOption>(
cbt::AlwaysRetryMutationPolicy().clone()));
// Normally this is not retried on transient failures, because the operation
// is not idempotent (each retry would set a different timestamp), in this
// case it would, because the table is setup to always retry.
cbt::SingleRowMutation mutation(
row_key, cbt::SetCell("fam", "some-column", "some-value"));
google::cloud::Status status = table.Apply(std::move(mutation));
if (!status.ok()) throw std::runtime_error(status.message());
}
std::string const & message() const
Modified Retry Policy Example
using ::google::cloud::Options;
namespace cbt = ::google::cloud::bigtable;
[](std::string const& project_id, std::string const& instance_id,
std::string const& table_id, std::string const& row_key) {
cbt::Table table(cbt::MakeDataConnection(),
cbt::TableResource(project_id, instance_id, table_id),
Options{}.set<cbt::DataRetryPolicyOption>(
cbt::DataLimitedErrorCountRetryPolicy(7).clone()));
cbt::SingleRowMutation mutation(
row_key, cbt::SetCell("fam", "some-column",
std::chrono::milliseconds(0), "some-value"));
google::cloud::Status status = table.Apply(std::move(mutation));
if (!status.ok()) throw std::runtime_error(status.message());
}

◆ Table() [2/5]

google::cloud::bigtable::Table::Table ( std::shared_ptr< DataClient client,
std::string const &  table_id 
)
inline

Constructor with default policies.

Parameters
clienthow to communicate with Cloud Bigtable, including credentials, the project id, and the instance id.
table_idthe table id within the instance defined by client. The full table name is client->instance_name() + "/tables/" + table_id.
Deprecated:
google::cloud::bigtable::DataConnection is the preferred way to communicate with the Bigtable Data API. To migrate existing code, see Migrating from DataClient.

◆ Table() [3/5]

google::cloud::bigtable::Table::Table ( std::shared_ptr< DataClient client,
std::string  app_profile_id,
std::string const &  table_id 
)
inline

Constructor with default policies.

Parameters
clienthow to communicate with Cloud Bigtable, including credentials, the project id, and the instance id.
app_profile_idthe app_profile_id needed for using the replication API.
table_idthe table id within the instance defined by client. The full table name is client->instance_name() + "/tables/" + table_id.
Deprecated:
google::cloud::bigtable::DataConnection is the preferred way to communicate with the Bigtable Data API. To migrate existing code, see Migrating from DataClient.

◆ Table() [4/5]

template<typename... Policies>
google::cloud::bigtable::Table::Table ( std::shared_ptr< DataClient client,
std::string const &  table_id,
Policies &&...  policies 
)
inline

Constructor with explicit policies.

The policies are passed by value, because this makes it easy for applications to create them.

Example
using namespace std::chrono_literals; // assuming C++14.
auto client = bigtable::MakeClient(...); // details omitted
bigtable::Table table(client, "my-table",
// Allow up to 20 minutes to retry operations
// Start with 50 milliseconds backoff, grow
// exponentially to 5 minutes.
// Only retry idempotent mutations.
Implement a simple exponential backoff policy.
Definition: rpc_backoff_policy.h:83
Implement a simple "keep trying for this time" retry policy.
Definition: rpc_retry_policy.h:153
Implements a policy that only accepts truly idempotent mutations.
Definition: idempotent_mutation_policy.h:55
The main interface to interact with data in a Cloud Bigtable table.
Definition: table.h:166
Parameters
clienthow to communicate with Cloud Bigtable, including credentials, the project id, and the instance id.
table_idthe table id within the instance defined by client. The full table name is client->instance_name() + "/tables/" + table_id.
policiesthe set of policy overrides for this object.
Template Parameters
Policiesthe types of the policies to override, the types must derive from one of the following types:
See also
SafeIdempotentMutationPolicy, AlwaysRetryMutationPolicy, ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
Deprecated:
google::cloud::bigtable::DataConnection is the preferred way to communicate with the Bigtable Data API. To migrate existing code, see Migrating from DataClient.

◆ Table() [5/5]

template<typename... Policies>
google::cloud::bigtable::Table::Table ( std::shared_ptr< DataClient client,
std::string  app_profile_id,
std::string const &  table_id,
Policies &&...  policies 
)
inline

Constructor with explicit policies.

The policies are passed by value, because this makes it easy for applications to create them.

Example
using namespace std::chrono_literals; // assuming C++14.
auto client = bigtable::MakeClient(...); // details omitted
bigtable::Table table(client, "app_id", "my-table",
// Allow up to 20 minutes to retry operations
// Start with 50 milliseconds backoff, grow
// exponentially to 5 minutes.
// Only retry idempotent mutations.
Parameters
clienthow to communicate with Cloud Bigtable, including credentials, the project id, and the instance id.
app_profile_idthe app_profile_id needed for using the replication API.
table_idthe table id within the instance defined by client. The full table name is client->instance_name() + "/tables/" + table_id.
policiesthe set of policy overrides for this object.
Template Parameters
Policiesthe types of the policies to override, the types must derive from one of the following types:
See also
SafeIdempotentMutationPolicy, AlwaysRetryMutationPolicy, ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
Deprecated:
google::cloud::bigtable::DataConnection is the preferred way to communicate with the Bigtable Data API. To migrate existing code, see Migrating from DataClient.

Member Function Documentation

◆ app_profile_id()

std::string const & google::cloud::bigtable::Table::app_profile_id ( ) const
inline

◆ Apply()

Status google::cloud::bigtable::Table::Apply ( SingleRowMutation  mut,
Options  opts = {} 
)

Attempts to apply the mutation to a row.

Parameters
mutthe mutation. Note that this function takes ownership (and then discards) the data in the mutation. In general, a SingleRowMutation can be used to modify and/or delete multiple cells, across different columns and column families.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
status of the operation.
Idempotency
This operation is idempotent if the provided mutations are idempotent. Note that google::cloud::bigtable::SetCell() without an explicit timestamp is not an idempotent operation.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work.
Example
namespace cbt = ::google::cloud::bigtable;
[](cbt::Table table, std::string const& row_key) {
auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
cbt::SingleRowMutation mutation(row_key);
mutation.emplace_back(
cbt::SetCell("fam", "column0", timestamp, "value for column0"));
mutation.emplace_back(
cbt::SetCell("fam", "column1", timestamp, "value for column1"));
auto status = table.Apply(std::move(mutation));
if (!status.ok()) throw std::runtime_error(status.message());
}

◆ AsyncApply()

future< Status > google::cloud::bigtable::Table::AsyncApply ( SingleRowMutation  mut,
Options  opts = {} 
)

Makes asynchronous attempts to apply the mutation to a row.

Parameters
mutthe mutation. Note that this function takes ownership (and then discards) the data in the mutation. In general, a SingleRowMutation can be used to modify and/or delete multiple cells, across different columns and column families.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Idempotency
This operation is idempotent if the provided mutations are idempotent. Note that google::cloud::bigtable::SetCell() without an explicit timestamp is not an idempotent operation.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
cbt::SingleRowMutation mutation(row_key);
mutation.emplace_back(
cbt::SetCell("fam", "column0", timestamp, "value for column0"));
mutation.emplace_back(
cbt::SetCell("fam", "column1", timestamp, "value for column1"));
table.AsyncApply(std::move(mutation));
auto status = status_future.get();
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Successfully applied mutation\n";
}

◆ AsyncBulkApply()

future< std::vector< FailedMutation > > google::cloud::bigtable::Table::AsyncBulkApply ( BulkMutation  mut,
Options  opts = {} 
)

Makes asynchronous attempts to apply mutations to multiple rows.

These mutations are applied in bulk, in a single MutateRowsRequest RPC. Failures are handled on a per mutation basis. If the result of a mutation is a permanent (non-retryable) error, or if a non-idempotent mutation fails for any reason, the mutation will not be retried. Only idempotent mutations that encounter transient (retryable) errors can be retried. These mutations are collected and retried in bulk. This function will continue to retry any remaining errors until this class's retry policy is exhausted.

It is possible that some mutations may not be attempted at all. These mutations are considered failing and will be returned.

Note
This function takes ownership (and then discards) the data in the mutation. In general, a BulkMutation can modify multiple rows, and the modifications for each row can change (or create) multiple cells, across different columns and column families.
Parameters
mutthe mutations
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
a future to be filled with a list of failed mutations, when the operation is complete.
Idempotency
This operation is idempotent if the provided mutations are idempotent. Note that google::cloud::bigtable::SetCell() without an explicit timestamp is not an idempotent operation.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
[](cbt::Table table) {
// Write several rows in a single operation, each row has some trivial data.
cbt::BulkMutation bulk;
for (int i = 0; i != 5000; ++i) {
// Note: This example uses sequential numeric IDs for simplicity, but
// this can result in poor performance in a production application.
// Since rows are stored in sorted order by key, sequential keys can
// result in poor distribution of operations across nodes.
//
// For more information about how to design a Bigtable schema for the
// best performance, see the documentation:
//
// https://cloud.google.com/bigtable/docs/schema-design
char buf[32];
snprintf(buf, sizeof(buf), "key-%06d", i);
cbt::SingleRowMutation mutation(buf);
mutation.emplace_back(
cbt::SetCell("fam", "col0", "value0-" + std::to_string(i)));
mutation.emplace_back(
cbt::SetCell("fam", "col1", "value2-" + std::to_string(i)));
mutation.emplace_back(
cbt::SetCell("fam", "col2", "value3-" + std::to_string(i)));
mutation.emplace_back(
cbt::SetCell("fam", "col3", "value4-" + std::to_string(i)));
bulk.emplace_back(std::move(mutation));
}
table.AsyncBulkApply(std::move(bulk))
.then([](future<std::vector<cbt::FailedMutation>> ft) {
auto failures = ft.get();
if (failures.empty()) {
std::cout << "All the mutations were successful\n";
return;
}
// By default, the `table` object uses the
// `SafeIdempotentMutationPolicy` which does not retry if any of the
// mutations fails and are not idempotent. In this example we simply
// print such failures, if any, and ignore them otherwise.
std::cerr << "The following mutations failed and were not retried:\n";
for (auto const& f : failures) {
std::cerr << "index[" << f.original_index() << "]=" << f.status()
<< "\n";
}
})
.get(); // block to simplify the example
}

◆ AsyncCheckAndMutateRow()

future< StatusOr< MutationBranch > > google::cloud::bigtable::Table::AsyncCheckAndMutateRow ( std::string  row_key,
Filter  filter,
std::vector< Mutation true_mutations,
std::vector< Mutation false_mutations,
Options  opts = {} 
)

Make an asynchronous request to conditionally mutate a row.

Parameters
row_keythe row key on which the conditional mutation will be performed
filterthe condition, depending on which the mutation will be performed
true_mutationsthe mutations which will be performed if filter is true
false_mutationsthe mutations which will be performed if filter is false
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Idempotency
This operation is always treated as non-idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
// Check if the latest value of the flip-flop column is "on".
cbt::Filter predicate = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("fam", "flip-flop", "flip-flop"),
cbt::Filter::Latest(1), cbt::Filter::ValueRegex("on"));
table.AsyncCheckAndMutateRow(row_key, std::move(predicate),
{cbt::SetCell("fam", "flip-flop", "off"),
cbt::SetCell("fam", "flop-flip", "on")},
{cbt::SetCell("fam", "flip-flop", "on"),
cbt::SetCell("fam", "flop-flip", "off")});
branch_future
auto response = f.get();
if (!response) throw std::move(response).status();
if (*response == cbt::MutationBranch::kPredicateMatched) {
std::cout << "The predicate was matched\n";
} else {
std::cout << "The predicate was not matched\n";
}
})
.get(); // block to simplify the example.
}
internal::then_helper< F, T >::future_t then(F &&func)

◆ AsyncReadModifyWriteRow()

template<typename... Args>
future< StatusOr< Row > > google::cloud::bigtable::Table::AsyncReadModifyWriteRow ( std::string  row_key,
bigtable::ReadModifyWriteRule  rule,
Args &&...  rules_and_options 
)
inline

Make an asynchronous request to atomically read and modify a row.

Template Parameters
Argsthis is zero or more ReadModifyWriteRules to apply on a row. Options to override the class-level options, such as retry, backoff, and idempotency policies are also be passed via this parameter pack.
Parameters
row_keythe row key on which modification will be performed
ruleto modify the row. Two types of rules are applied here AppendValue which will read the existing value and append the text provided to the value. IncrementAmount which will read the existing uint64 big-endian-int and add the value provided. Both rules accept the family and column identifier to modify.
rules_and_optionsis the zero or more ReadModifyWriteRules to apply on a row. Options to override the class-level options, such as retry, backoff, and idempotency policies are also be passed via this parameter pack.
Returns
a future, that becomes satisfied when the operation completes, at that point the future has the contents of all modified cells.
Idempotency
This operation is always treated as non-idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
future<StatusOr<cbt::Row>> row_future = table.AsyncReadModifyWriteRow(
std::move(row_key),
cbt::ReadModifyWriteRule::AppendValue("fam", "list", ";element"));
row_future
auto row = f.get();
// As the modify in this example is not idempotent, and this example
// does not attempt to retry if there is a failure, we simply print
// such failures, if any, and otherwise ignore them.
if (!row) {
std::cout << "Failed to append row: " << row.status().message()
<< "\n";
return;
}
std::cout << "Successfully appended to " << row->row_key() << "\n";
})
.get(); // block to simplify example.
}

◆ AsyncReadRow()

future< StatusOr< std::pair< bool, Row > > > google::cloud::bigtable::Table::AsyncReadRow ( std::string  row_key,
Filter  filter,
Options  opts = {} 
)

Asynchronously read and return a single row from the table.

Parameters
row_keythe row to read.
filtera filter expression, can be used to select a subset of the column families and columns in the row.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
a future satisfied when the operation completes, fails permanently or keeps failing transiently, but the retry policy has been exhausted. The future will return a tuple. The first element is a boolean, with value false if the row does not exist. If the first element is true the second element has the contents of the Row. Note that the contents may be empty if the filter expression removes all column families and columns.
Idempotency
This is a read-only operation and therefore it is always idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](google::cloud::bigtable::Table table, std::string const& row_key) {
// Filter the results, only include the latest value on each cell.
cbt::Filter filter = cbt::Filter::Latest(1);
table.AsyncReadRow(row_key, std::move(filter))
.then(
[row_key](future<StatusOr<std::pair<bool, cbt::Row>>> row_future) {
// Read a row, this returns a tuple (bool, row)
auto tuple = row_future.get();
if (!tuple) throw std::move(tuple).status();
if (!tuple->first) {
std::cout << "Row " << row_key << " not found\n";
return;
}
std::cout << "key: " << tuple->second.row_key() << "\n";
for (auto const& cell : tuple->second.cells()) {
std::cout << " " << cell.family_name() << ":"
<< cell.column_qualifier() << " = <";
if (cell.column_qualifier() == "counter") {
// This example uses "counter" to store 64-bit numbers in
// big-endian format, extract them as follows:
std::cout
<< cell.decode_big_endian_integer<std::int64_t>().value();
} else {
std::cout << cell.value();
}
std::cout << ">\n";
}
})
.get(); // block to simplify the example
}
future< StatusOr< std::pair< bool, Row > > > AsyncReadRow(std::string row_key, Filter filter, Options opts={})
Asynchronously read and return a single row from the table.

◆ AsyncReadRows() [1/2]

template<typename RowFunctor , typename FinishFunctor >
void google::cloud::bigtable::Table::AsyncReadRows ( RowFunctor  on_row,
FinishFunctor  on_finish,
RowSet  row_set,
Filter  filter,
Options  opts = {} 
)
inline

Asynchronously reads a set of rows from the table.

Parameters
on_rowthe callback to be invoked on each successfully read row; it should be invocable with Row and return a future<bool>; the returned future<bool> should be satisfied with true when the user is ready to receive the next callback and with false when the user doesn't want any more rows; if on_row throws, the results are undefined
on_finishthe callback to be invoked when the stream is closed; it should be invocable with Status and not return anything; it will always be called as the last callback; if on_finish throws, the results are undefined
row_setthe rows to read from.
filteris applied on the server-side to data in the rows.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Template Parameters
RowFunctorthe type of the on_row callback.
FinishFunctorthe type of the on_finish callback.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::make_ready_future;
using ::google::cloud::promise;
using ::google::cloud::Status;
[](cbt::Table table) {
// Create the range of rows to read.
auto range = cbt::RowRange::Range("key-000010", "key-000020");
// Filter the results, only include values from the "col0" column in the
// "fam" column family, and only get the latest value.
auto filter = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("fam", "col0", "col0"),
cbt::Filter::Latest(1));
promise<Status> stream_status_promise;
// Read and print the rows.
table.AsyncReadRows(
[](cbt::Row const& row) {
if (row.cells().size() != 1) {
std::cout << "Unexpected number of cells in " << row.row_key()
<< "\n";
return make_ready_future(false);
}
auto const& cell = row.cells().at(0);
std::cout << cell.row_key() << " = [" << cell.value() << "]\n";
return make_ready_future(true);
},
[&stream_status_promise](Status const& stream_status) {
stream_status_promise.set_value(stream_status);
},
range, filter);
Status stream_status = stream_status_promise.get_future().get();
if (!stream_status.ok()) throw std::runtime_error(stream_status.message());
}
future< T > get_future()
void set_value(T value)
future< void > make_ready_future()

◆ AsyncReadRows() [2/2]

template<typename RowFunctor , typename FinishFunctor >
void google::cloud::bigtable::Table::AsyncReadRows ( RowFunctor  on_row,
FinishFunctor  on_finish,
RowSet  row_set,
std::int64_t  rows_limit,
Filter  filter,
Options  opts = {} 
)
inline

Asynchronously reads a set of rows from the table.

Parameters
on_rowthe callback to be invoked on each successfully read row; it should be invocable with Row and return a future<bool>; the returned future<bool> should be satisfied with true when the user is ready to receive the next callback and with false when the user doesn't want any more rows; if on_row throws, the results are undefined
on_finishthe callback to be invoked when the stream is closed; it should be invocable with Status and not return anything; it will always be called as the last callback; if on_finish throws, the results are undefined
row_setthe rows to read from.
rows_limitthe maximum number of rows to read. Cannot be a negative number or zero. Use AsyncReadRows(RowSet, Filter) to read all matching rows.
filteris applied on the server-side to data in the rows.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Template Parameters
RowFunctorthe type of the on_row callback.
FinishFunctorthe type of the on_finish callback.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread. The callbacks passed to this function may be executed on any thread running the provided completion queue.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::make_ready_future;
using ::google::cloud::promise;
using ::google::cloud::Status;
[](cbt::Table table, std::int64_t const& limit) {
// Create the range of rows to read.
auto range = cbt::RowRange::Range("key-000010", "key-000020");
// Filter the results, only include values from the "col0" column in the
// "fam" column family, and only get the latest value.
auto filter = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("fam", "col0", "col0"),
cbt::Filter::Latest(1));
promise<Status> stream_status_promise;
// Read and print the rows.
table.AsyncReadRows(
[](cbt::Row const& row) {
if (row.cells().size() != 1) {
std::cout << "Unexpected number of cells in " << row.row_key()
<< "\n";
return make_ready_future(false);
}
auto const& cell = row.cells().at(0);
std::cout << cell.row_key() << " = [" << cell.value() << "]\n";
return make_ready_future(true);
},
[&stream_status_promise](Status const& stream_status) {
stream_status_promise.set_value(stream_status);
},
range, limit, filter);
Status stream_status = stream_status_promise.get_future().get();
if (!stream_status.ok()) throw std::runtime_error(stream_status.message());
}

◆ AsyncSampleRows()

future< StatusOr< std::vector< bigtable::RowKeySample > > > google::cloud::bigtable::Table::AsyncSampleRows ( Options  opts = {})

Asynchronously obtains a sample of the row keys in the table, including approximate data sizes.

Returns
a future, that becomes satisfied when the operation completes.
Note
The sample may only include one element for small tables. In addition, the sample may include row keys that do not exist on the table, and may include the empty row key to indicate "end of table".
Idempotency
This operation is always treated as idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Examples
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbt::Table table) {
table.AsyncSampleRows();
samples_future
.then([](future<StatusOr<std::vector<cbt::RowKeySample>>> f) {
auto samples = f.get();
if (!samples) throw std::move(samples).status();
for (auto const& sample : *samples) {
std::cout << "key=" << sample.row_key << " - "
<< sample.offset_bytes << "\n";
}
})
.get(); // block to simplify the example.
}

◆ BulkApply()

std::vector< FailedMutation > google::cloud::bigtable::Table::BulkApply ( BulkMutation  mut,
Options  opts = {} 
)

Attempts to apply mutations to multiple rows.

These mutations are applied in bulk, in a single MutateRowsRequest RPC. Failures are handled on a per mutation basis. If the result of a mutation is a permanent (non-retryable) error, or if a non-idempotent mutation fails for any reason, the mutation will not be retried. Only idempotent mutations that encounter transient (retryable) errors can be retried. These mutations are collected and retried in bulk. This function will continue to retry any remaining errors until this class's retry policy is exhausted.

It is possible that some mutations may not be attempted at all. These mutations are considered failing and will be returned.

Note
This function takes ownership (and then discards) the data in the mutation. In general, a BulkMutation can modify multiple rows, and the modifications for each row can change (or create) multiple cells, across different columns and column families.
Parameters
mutthe mutations
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
a list of failed mutations
Idempotency
This operation is idempotent if the provided mutations are idempotent. Note that google::cloud::bigtable::SetCell() without an explicit timestamp is not an idempotent operation.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
[](cbt::Table table) {
// Write several rows in a single operation, each row has some trivial data.
cbt::BulkMutation bulk;
for (int i = 0; i != 5000; ++i) {
// Note: This example uses sequential numeric IDs for simplicity, but
// this can result in poor performance in a production application.
// Since rows are stored in sorted order by key, sequential keys can
// result in poor distribution of operations across nodes.
//
// For more information about how to design a Bigtable schema for the
// best performance, see the documentation:
//
// https://cloud.google.com/bigtable/docs/schema-design
char buf[32];
snprintf(buf, sizeof(buf), "key-%06d", i);
cbt::SingleRowMutation mutation(buf);
mutation.emplace_back(
cbt::SetCell("fam", "col0", "value0-" + std::to_string(i)));
mutation.emplace_back(
cbt::SetCell("fam", "col1", "value1-" + std::to_string(i)));
bulk.emplace_back(std::move(mutation));
}
std::vector<cbt::FailedMutation> failures =
table.BulkApply(std::move(bulk));
if (failures.empty()) {
std::cout << "All mutations applied successfully\n";
return;
}
// By default, the `table` object uses the `SafeIdempotentMutationPolicy`
// which does not retry if any of the mutations fails and are
// not-idempotent. In this example we simply print such failures, if any,
// and ignore them otherwise.
std::cerr << "The following mutations failed and were not retried:\n";
for (auto const& f : failures) {
std::cerr << "index[" << f.original_index() << "]=" << f.status() << "\n";
}
}

◆ CheckAndMutateRow()

StatusOr< MutationBranch > google::cloud::bigtable::Table::CheckAndMutateRow ( std::string  row_key,
Filter  filter,
std::vector< Mutation true_mutations,
std::vector< Mutation false_mutations,
Options  opts = {} 
)

Atomic test-and-set for a row using filter expressions.

Atomically check the value of a row using a filter expression. If the expression passes (meaning at least one element is returned by it), one set of mutations is applied. If the filter does not pass, a different set of mutations is applied. The changes are atomically applied in the server.

Parameters
row_keythe row to modify.
filterthe filter expression.
true_mutationsthe mutations for the "filter passed" case.
false_mutationsthe mutations for the "filter did not pass" case.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
true if the filter passed.
Idempotency
This operation is always treated as non-idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Check for Value Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
// Check if the latest value of the flip-flop column is "on".
cbt::Filter predicate = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("fam", "flip-flop", "flip-flop"),
cbt::Filter::Latest(1), cbt::Filter::ValueRegex("on"));
// If the predicate matches, change the latest value to "off", otherwise,
// change the latest value to "on". Modify the "flop-flip" column at the
// same time.
table.CheckAndMutateRow(row_key, std::move(predicate),
{cbt::SetCell("fam", "flip-flop", "off"),
cbt::SetCell("fam", "flop-flip", "on")},
{cbt::SetCell("fam", "flip-flop", "on"),
cbt::SetCell("fam", "flop-flip", "off")});
if (!branch) throw std::move(branch).status();
if (*branch == cbt::MutationBranch::kPredicateMatched) {
std::cout << "The predicate was matched\n";
} else {
std::cout << "The predicate was not matched\n";
}
}
Check for Cell Presence Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
// Check if the latest value of the "test-column" column is present,
// regardless of its value.
cbt::Filter predicate = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("fam", "test-column", "test-column"),
cbt::Filter::Latest(1));
// If the predicate matches, do nothing, otherwise set the
// "had-test-column" to "false":
StatusOr<cbt::MutationBranch> branch = table.CheckAndMutateRow(
row_key, std::move(predicate), {},
{cbt::SetCell("fam", "had-test-column", "false")});
if (!branch) throw std::move(branch).status();
if (*branch == cbt::MutationBranch::kPredicateMatched) {
std::cout << "The predicate was matched\n";
} else {
std::cout << "The predicate was not matched\n";
}
}

◆ instance_id()

std::string const & google::cloud::bigtable::Table::instance_id ( ) const
inline

◆ project_id()

std::string const & google::cloud::bigtable::Table::project_id ( ) const
inline

◆ ReadModifyWriteRow()

template<typename... Args>
StatusOr< Row > google::cloud::bigtable::Table::ReadModifyWriteRow ( std::string  row_key,
bigtable::ReadModifyWriteRule  rule,
Args &&...  rules_and_options 
)
inline

Atomically read and modify the row in the server, returning the resulting row.

Template Parameters
Argsthis is zero or more ReadModifyWriteRules to apply on a row. Options to override the class-level options, such as retry, backoff, and idempotency policies are also be passed via this parameter pack.
Parameters
row_keythe row to read
ruleto modify the row. Two types of rules are applied here AppendValue which will read the existing value and append the text provided to the value. IncrementAmount which will read the existing uint64 big-endian-int and add the value provided. Both rules accept the family and column identifier to modify.
rules_and_optionsis the zero or more ReadModifyWriteRules to apply on a row. Options to override the class-level options, such as retry, backoff, and idempotency policies are also be passed via this parameter pack.
Returns
the new contents of all modified cells.
Idempotency
This operation is always treated as non-idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::string const& row_key) {
StatusOr<cbt::Row> row = table.ReadModifyWriteRow(
row_key, cbt::ReadModifyWriteRule::IncrementAmount("fam", "counter", 1),
cbt::ReadModifyWriteRule::AppendValue("fam", "list", ";element"));
// As the modify in this example is not idempotent, and this example
// does not attempt to retry if there is a failure, we simply print
// such failures, if any, and otherwise ignore them.
if (!row) {
std::cout << "Failed to append row: " << row.status().message() << "\n";
return;
}
// Print the contents of the row
std::cout << row->row_key() << "\n";
for (auto const& cell : row->cells()) {
std::cout << " " << cell.family_name() << ":"
<< cell.column_qualifier() << " = <";
if (cell.column_qualifier() == "counter") {
// This example uses "counter" to store 64-bit numbers in big-endian
// format, extract them as follows:
std::cout << cell.decode_big_endian_integer<std::int64_t>().value();
} else {
std::cout << cell.value();
}
std::cout << ">\n";
}
}

◆ ReadRow()

StatusOr< std::pair< bool, Row > > google::cloud::bigtable::Table::ReadRow ( std::string  row_key,
Filter  filter,
Options  opts = {} 
)

Read and return a single row from the table.

Parameters
row_keythe row to read.
filtera filter expression, can be used to select a subset of the column families and columns in the row.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Returns
a tuple, the first element is a boolean, with value false if the row does not exist. If the first element is true the second element has the contents of the Row. Note that the contents may be empty if the filter expression removes all column families and columns.
Idempotency
This is a read-only operation and therefore it is always idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](google::cloud::bigtable::Table table, std::string const& row_key) {
row_key, cbt::Filter::ColumnName("stats_summary", "os_build"));
if (!tuple) throw std::move(tuple).status();
if (!tuple->first) {
std::cout << "Row " << row_key << " not found\n";
return;
}
PrintRow(tuple->second);
}
StatusOr< std::pair< bool, Row > > ReadRow(std::string row_key, Filter filter, Options opts={})
Read and return a single row from the table.

◆ ReadRows() [1/2]

RowReader google::cloud::bigtable::Table::ReadRows ( RowSet  row_set,
Filter  filter,
Options  opts = {} 
)

Reads a set of rows from the table.

Parameters
row_setthe rows to read from.
filteris applied on the server-side to data in the rows.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Idempotency
This is a read-only operation and therefore it is always idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread. The values returned by different calls are independent with respect to thread-safety, please see the RowReader documentation for more details.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table) {
// Read and print the rows.
for (auto& row :
table.ReadRows(cbt::RowRange::Range("phone#4c410523#20190501",
"phone#4c410523#201906201"),
cbt::Filter::PassAllFilter())) {
if (!row) throw std::move(row).status();
PrintRow(*row);
}
}

◆ ReadRows() [2/2]

RowReader google::cloud::bigtable::Table::ReadRows ( RowSet  row_set,
std::int64_t  rows_limit,
Filter  filter,
Options  opts = {} 
)

Reads a limited set of rows from the table.

Parameters
row_setthe rows to read from.
rows_limitthe maximum number of rows to read. Cannot be a negative number or zero. Use ReadRows(RowSet, Filter) to read all matching rows.
filteris applied on the server-side to data in the rows.
opts(Optional) Override the class-level options, such as retry, backoff, and idempotency policies.
Idempotency
This is a read-only operation and therefore it is always idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread. The values returned by different calls are independent with respect to thread-safety, please see the RowReader documentation for more details.
Example
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table, std::int64_t limit) {
// Create the range of rows to read.
auto range = cbt::RowRange::Range("phone#4c410523#20190501",
"phone#4c410523#20190502");
// Filter the results, only include values from the "connected_wifi" column
// in the "stats_summary" column family, and only get the latest value.
cbt::Filter filter = cbt::Filter::Chain(
cbt::Filter::ColumnRangeClosed("stats_summary", "connected_wifi",
"connected_wifi"),
cbt::Filter::Latest(1));
// Read and print the first rows in the range, within the row limit.
for (auto& row : table.ReadRows(range, limit, filter)) {
if (!row) throw std::move(row).status();
if (row->cells().size() != 1) {
std::ostringstream os;
os << "Unexpected number of cells in " << row->row_key();
throw std::runtime_error(os.str());
}
auto const& cell = row->cells().at(0);
std::cout << cell.row_key() << " = [" << cell.value() << "]\n";
}
}

◆ SampleRows()

StatusOr< std::vector< bigtable::RowKeySample > > google::cloud::bigtable::Table::SampleRows ( Options  opts = {})

Sample of the row keys in the table, including approximate data sizes.

Note
The sample may only include one element for small tables. In addition, the sample may include row keys that do not exist on the table, and may include the empty row key to indicate "end of table".
Idempotency
This operation is always treated as idempotent.
Thread-safety
Two threads concurrently calling this member function on the same instance of this class are not guaranteed to work. Consider copying the object and using different copies in each thread.
Examples
namespace cbt = ::google::cloud::bigtable;
using ::google::cloud::StatusOr;
[](cbt::Table table) {
StatusOr<std::vector<cbt::RowKeySample>> samples = table.SampleRows();
if (!samples) throw std::move(samples).status();
for (auto const& sample : *samples) {
std::cout << "key=" << sample.row_key << " - " << sample.offset_bytes
<< "\n";
}
}

◆ table_id()

std::string const & google::cloud::bigtable::Table::table_id ( ) const
inline

◆ table_name()

std::string const & google::cloud::bigtable::Table::table_name ( ) const
inline

◆ WithNewTarget() [1/2]

Table google::cloud::bigtable::Table::WithNewTarget ( std::string  project_id,
std::string  instance_id,
std::string  app_profile_id,
std::string  table_id 
) const
inline

Returns a Table that reuses the connection and configuration of this Table, but with a different resource name.

◆ WithNewTarget() [2/2]

Table google::cloud::bigtable::Table::WithNewTarget ( std::string  project_id,
std::string  instance_id,
std::string  table_id 
) const
inline

Returns a Table that reuses the connection and configuration of this Table, but with a different resource name.

Note
The app profile id is copied from this Table.

Friends And Related Function Documentation

◆ MutationBatcher

friend class MutationBatcher
friend