Reference documentation and code samples for the Cloud Bigtable Client class Table.
A table instance can be used to read rows and to perform insert, update, and delete operations.
Example:
use Google\Cloud\Bigtable\BigtableClient;
$bigtable = new BigtableClient();
$table = $bigtable->table('my-instance', 'my-table');
Namespace
Google \ Cloud \ BigtableMethods
__construct
Create a table instance.
gapicClient
tableName
string
The full table name. Must match the following pattern: projects/{project}/instances/{instance}/tables/{table}.
options
array
Configuration options.
↳ appProfileId
string
This value specifies routing for replication. Defaults tothe "default" application profile.
↳ headers
array
Headers to be passed with each request.
↳ retries
int
Number of times to retry. Defaults to 3
. This settings only applies to Google\Cloud\Bigtable\Table::mutateRows()
, Google\Cloud\Bigtable\Table::upsert()
and Google\Cloud\Bigtable\Table::readRows()}. </xref
mutateRows
Mutates rows in a table.
Example:
use Google\Cloud\Bigtable\Mutations;
$mutations = (new Mutations)
->upsert('cf1', 'cq1', 'value1', 1534183334215000);
$table->mutateRows(['r1' => $mutations]);
rowMutations
array
An associative array with the key being the row key and the value being the Google\Cloud\Bigtable\Mutations to perform.
options
array
[optional] Configuration options.
void
mutateRow
Mutates a row atomically. Cells already present in the row are left
unchanged unless explicitly changed by mutations
.
Example:
use Google\Cloud\Bigtable\Mutations;
$mutations = (new Mutations)
->upsert('cf1', 'cq1', 'value1', 1534183334215000);
$table->mutateRow('r1', $mutations);
rowKey
string
The row key of the row to mutate.
mutations
options
array
Configuration options.
↳ retries
int
Number of times to retry. Defaults to 3
.
void
upsert
Insert/update rows in a table.
Example:
$table->upsert([
'r1' => [
'cf1' => [
'cq1' => [
'value'=>'value1',
'timeStamp' => 1534183334215000
]
]
]
]);
rows
array[]
An array of rows.
options
array
Configuration options.
↳ retries
int
Number of times to retry. Defaults to 3
.
void
readRows
Read rows from the table.
Example:
$rows = $table->readRows();
foreach ($rows as $key => $row) {
echo $key . ': ' . print_r($row, true) . PHP_EOL;
}
// Specify a set of row ranges.
$rows = $table->readRows([
'rowRanges' => [
[
'startKeyOpen' => 'jefferson',
'endKeyOpen' => 'lincoln'
]
]
]);
foreach ($rows as $key => $row) {
echo $key . ': ' . print_r($row, true) . PHP_EOL;
}
options
array
Configuration options.
↳ rowKeys
string[]
A set of row keys to read.
↳ rowRanges
array
A set of row ranges. Each row range is an associative array which may contain a start key ( startKeyClosed
or startKeyOpen
) and/or an end key ( endKeyOpen
or endKeyClosed
).
↳ filter
FilterInterface
A filter used to take an input row and produce an alternate view of the row based on the specified rules. To learn more please see Google\Cloud\Bigtable\Filter which provides static factory methods for the various filter types.
↳ rowsLimit
int
The number of rows to scan.
↳ retries
int
Number of times to retry. Defaults to 3
.
readRow
Read a single row from the table.
Example:
$row = $table->readRow('jefferson');
print_r($row);
rowKey
string
The row key to read.
options
array
[optional] Configuration options.
array|null
readModifyWriteRow
Modifies a row atomically on the server. The method reads the latest existing timestamp and value from the specified columns and writes a new entry based on pre-defined read/modify/write rules. The new value for the timestamp is the greater of the existing timestamp or the current server time. The method returns the new contents of all modified cells.
Example:
use Google\Cloud\Bigtable\ReadModifyWriteRowRules;
$rules = (new ReadModifyWriteRowRules)
->append('cf1', 'cq1', 'value12');
$row = $table->readModifyWriteRow('rk1', $rules);
print_r($row);
// Increments value
use Google\Cloud\Bigtable\DataUtil;
use Google\Cloud\Bigtable\ReadModifyWriteRowRules;
use Google\Cloud\Bigtable\Mutations;
$mutations = (new Mutations)
->upsert('cf1', 'cq1', DataUtil::intToByteString(2));
$table->mutateRows(['rk1' => $mutations]);
$rules = (new ReadModifyWriteRowRules)
->increment('cf1', 'cq1', 3);
$row = $table->readModifyWriteRow('rk1', $rules);
print_r($row);
rowKey
string
The row key to read.
rules
options
array
[optional] Configuration options.
array
sampleRowKeys
Returns a sample of row keys in the table. The returned row keys will delimit contiguous sections of the table of approximately equal size, which can be used to break up the data for distributed tasks like mapreduces.
Example:
$rowKeyStream = $table->sampleRowKeys();
foreach ($rowKeyStream as $rowKey) {
print_r($rowKey) . PHP_EOL;
}
options
array
[optional] Configuration options.
Generator
checkAndMutateRow
Mutates the specified row atomically based on output of the filter.
Example:
use Google\Cloud\Bigtable\Mutations;
$mutations = (new Mutations)->upsert('family', 'qualifier', 'value');
$result = $table->checkAndMutateRow('rk1', ['trueMutations' => $mutations]);
// With predicate filter
use Google\Cloud\Bigtable\Filter;
use Google\Cloud\Bigtable\Mutations;
$mutations = (new Mutations)->upsert('family', 'qualifier', 'value');
$predicateFilter = Filter::qualifier()->exactMatch('cq');
$options = ['predicateFilter' => $predicateFilter, 'trueMutations' => $mutations];
$result = $table->checkAndMutateRow('rk1', $options);
rowKey
string
The row key to mutate row conditionally.
options
array
Configuration options.
↳ predicateFilter
FilterInterface
The filter to be applied to the specified row. Depending on whether or not any results are yielded, either the trueMutations or falseMutations will be executed. If unset, checks that the row contains any values at all. Only a single condition can be set, however that filter can be Google\Cloud\Bigtable\Filter::chain() or Google\Cloud\Bigtable\Filter::interleave() which can wrap multiple other filters. WARNING: Google\Cloud\Bigtable\Filter::condition() is not supported.
↳ trueMutations
Mutations
Mutations to be atomically applied when the predicate filter's condition yields at least one cell when applied to the row. Please note either trueMutations
or falseMutations
must be provided.
↳ falseMutations
Mutations
Mutations to be atomically applied when the predicate filter's condition does not yield any cells when applied to the row. Please note either trueMutations
or falseMutations
must be provided.
bool