Cloud Bigtable Client - Class Table (2.17.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
Name
Description
gapicClient
V2\Client\BigtableClient

The GAPIC client to use in order to send requests.

serializer
Google\ApiCore\Serializer

The serializer instance to encode/decode messages.

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.

↳ retrySettings.maxRetries
int

Number of times to retry. Defaults to 3 . This settings only applies to Table::mutateRows() , Table::upsert() and 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
Name
Description
rowMutations
array

An associative array with the key being the row key and the value being the Mutations to perform.

options
array

Configuration options.

 @option RetrySettings|array $retrySettings {
    Only $maxRetries and $totalTimeoutMillis work for RetrySettings in this API.

    @option int $maxRetries Number of times to retry. **Defaults to** `3`.
    @option int $totalTimeoutMillis The max accumulative timeout in total.
} 
Returns
Type
Description
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
Name
Description
rowKey
string

The row key of the row to mutate.

mutations
Mutations

Mutations to apply on row.

options
array

Configuration options.

 @option RetrySettings|array $retrySettings {
    Only $maxRetries and $totalTimeoutMillis work for RetrySettings in this API.

    @option int $maxRetries Number of times to retry. **Defaults to** `3`.
    @option int $totalTimeoutMillis The max accumulative timeout in total.
} 
Returns
Type
Description
void

upsert

Insert/update rows in a table.

Example:

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

An array of rows.

options
array

Configuration options.

↳ retrySettings
RetrySettings|array

{ Only $maxRetries and $totalTimeoutMillis work for RetrySettings in this API.

↳ maxRetries
int

Number of times to retry. Defaults to 3 .

↳ totalTimeoutMillis
int

The max accumulative timeout in total for the operation. }

Returns
Type
Description
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
Name
Description
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 Filter which provides static factory methods for the various filter types.

↳ rowsLimit
int

The number of rows to scan.

↳ retrySettings
RetrySettings|array

{ Only $maxRetries and $totalTimeoutMillis work for RetrySettings in this API.

↳ maxRetries
int

Number of times to retry. Defaults to 3 .

↳ totalTimeoutMillis
int

The max accumulative timeout in total for the operation. }

Returns
Type
Description

readRow

Read a single row from the table.

Example:

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

print_r($row); 
Parameters
Name
Description
rowKey
string

The row key to read.

options
array

[optional] Configuration options.

Returns
Type
Description
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
Name
Description
rowKey
string

The row key to read.

rules
ReadModifyWriteRowRules

Rules to apply on row.

options
array

[optional] Configuration options.

Returns
Type
Description
array
Returns 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
Name
Description
options
array

[optional] Configuration options.

Returns
Type
Description
Generator < array >
A 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
Name
Description
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 Filter::chain() or Filter::interleave() which can wrap multiple other filters. WARNING: 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
Type
Description
bool
Returns true if predicate filter yielded any output, false otherwise.
Create a Mobile Website
View Site in Mobile | Classic
Share by: