# Cloud Bigtable Client - Class Table (2.25.0)

2.25.0 (latest) 2.24.0 2.23.0 2.22.0 2.21.1 2.20.2 2.19.2 2.18.0 2.17.1 2.16.0 2.15.0 2.14.0 2.13.0 2.12.0 2.11.1 2.9.1 2.8.0 2.7.0 2.6.3 2.5.0 2.4.0 2.3.0 2.2.1 2.1.0 2.0.1 1.32.1 1.31.1 1.30.0 1.29.2 1.28.3 1.27.0 1.26.2 1.25.0 1.24.1 1.23.0 1.22.2 1.21.1 1.20.3 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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/V2.Client.BigtableClient` The GAPIC client to use in order to send requests. |
| `serializer` | `https://docs.cloud.google.com/php/docs/reference/gax/latest/Serializer.html` 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 to** the "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()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Table#_Google_Cloud_Bigtable_Table__mutateRows__), [Table::upsert()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Table#_Google_Cloud_Bigtable_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](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/ChunkFormatter` |   |

### 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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter.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()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter#_Google_Cloud_Bigtable_Filter__chain__) or [Filter::interleave()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter#_Google_Cloud_Bigtable_Filter__interleave__) which can wrap multiple other filters. WARNING: [Filter::condition()](https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/Filter#_Google_Cloud_Bigtable_Filter__condition__) is not supported. |
| `↳ trueMutations` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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` | `https://docs.cloud.google.com/php/docs/reference/cloud-bigtable/latest/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. |