Cloud Bigtable Client - Class Table (1.27.0)

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 \ Bigtable

Methods

__construct

Create a table instance.

Parameters
NameDescription
gapicClient Google\Cloud\Bigtable\V2\BigtableClient

The GAPIC client used to make requests.

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 to the "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\Google\Cloud\Bigtable\Table::mutateRows(), Google\Cloud\Bigtable\Google\Cloud\Bigtable\Table::upsert() and Google\Cloud\Bigtable\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]);
Parameters
NameDescription
rowMutations array

An associative array with the key being the row key and the value being the Google\Cloud\Bigtable\Google\Cloud\Bigtable\Mutations to perform.

options array

[optional] Configuration options.

Returns
TypeDescription
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);
Parameters
NameDescription
rowKey string

The row key of the row to mutate.

mutations Google\Cloud\Bigtable\Mutations

Mutations to apply on row.

options array

Configuration options.

↳ retries int

Number of times to retry. Defaults to 3.

Returns
TypeDescription
void

upsert

Insert/update rows in a table.

Example:

$table->upsert([
    'r1' => [
        'cf1' => [
            'cq1' => [
                'value'=>'value1',
                'timeStamp' => 1534183334215000
             ]
        ]
    ]
]);
Parameters
NameDescription
rows array[]

An array of rows.

options array

Configuration options.

↳ retries int

Number of times to retry. Defaults to 3.

Returns
TypeDescription
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;
}
Parameters
NameDescription
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\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.

Returns
TypeDescription
Google\Cloud\Bigtable\ChunkFormatter

readRow

Read a single row from the table.

Example:

$row = $table->readRow('jefferson');

print_r($row);
Parameters
NameDescription
rowKey string

The row key to read.

options array

[optional] Configuration options.

Returns
TypeDescription
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);
Parameters
NameDescription
rowKey string

The row key to read.

rules Google\Cloud\Bigtable\ReadModifyWriteRowRules

Rules to apply on row.

options array

[optional] Configuration options.

Returns
TypeDescription
arrayReturns array containing all column family keyed by family name.

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;
}
Parameter
NameDescription
options array

[optional] Configuration options.

Returns
TypeDescription
GeneratorA list of associative arrays, each with the keys `rowKey` and `offset`.

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);
Parameters
NameDescription
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\Google\Cloud\Bigtable\Filter::chain() or Google\Cloud\Bigtable\Google\Cloud\Bigtable\Filter::interleave() which can wrap multiple other filters. WARNING: Google\Cloud\Bigtable\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.

Returns
TypeDescription
boolReturns true if predicate filter yielded any output, false otherwise.