Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DataClient -> Table and add BigtableClient #1387

Merged
merged 12 commits into from
Nov 2, 2018
144 changes: 144 additions & 0 deletions Bigtable/src/BigtableClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?php
/**
* Copyright 2018, Google LLC All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Bigtable;

use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\Transport\TransportInterface;
use Google\ApiCore\ValidationException;
use Google\Auth\FetchAuthTokenInterface;
use Google\Cloud\Bigtable\V2\BigtableClient as GapicClient;
use Google\Cloud\Core\ClientTrait;

/**
* Google Cloud Bigtable is Google's NoSQL Big Data database service.
* Find more information at the
* [Google Cloud Bigtable Docs](https://cloud.google.com/bigtable/docs/).
*
* Example:
* ```
* use Google\Cloud\Bigtable\BigtableClient;
*
* $bigtable = new BigtableClient();
* ```
*/
class BigtableClient
{
use ClientTrait;

const VERSION = '0.5.3';

/**
* @var GapicClient
*/
private $gapicClient;

/**
* Create a Bigtable client.
*
* @param array $config [optional] {
* Configuration options.
*
* @type string $projectId The project ID from the Google Developer's
* Console.
* @type string $serviceAddress The address of the API remote host. May
* optionally include the port, formatted as "<uri>:<port>".
* **Defaults to** 'bigtable.googleapis.com:443'.
* @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials
* The credentials to be used by the client to authorize API calls.
* This option accepts either a path to a credentials file, or a
* decoded credentials file as a PHP array.
* *Advanced usage*: In addition, this option can also accept a
* pre-constructed {@see Google\Auth\FetchAuthTokenInterface} object
* or {@see Google\ApiCore\CredentialsWrapper} object. Note that when
* one of these objects are provided, any settings in
* $config['credentialsConfig'] will be ignored.
* @type array $credentialsConfig Options used to configure credentials,
* including auth token caching, for the client. For a full list of
* supporting configuration options, see
* {@see Google\ApiCore\CredentialsWrapper}.
* @type bool $disableRetries Determines whether or not retries defined by
* the client configuration should be disabled. **Defaults to**
* `false`.
* @type string|array $clientConfig Client method configuration, including
* retry settings. This option can be either a path to a JSON file, or
* a PHP array containing the decoded JSON data.
* @type string|TransportInterface $transport The transport used for
* executing network requests. May be either the string `rest` or
* `grpc`. **Defaults to** `grpc` if gRPC support is detected on
* the system. *Advanced usage*: Additionally, it is possible to
* pass in an already instantiated
* {@see Google\ApiCore\Transport\TransportInterface} object. Note
* that when this object is provided, any settings in
* $config['transportConfig'] and the $config['serviceAddress']
* setting will be ignored.
* @type array $transportConfig Configuration options that will be used to
* construct the transport. Options for each supported transport type
* should be passed in a key for that transport. For example:
* $transportConfig = [
* 'grpc' => [...],
* 'rest' => [...]
* ];
* See {@see Google\ApiCore\Transport\GrpcTransport} and
* {@see Google\ApiCore\Transport\RestTransport} for
* the supported options.
* }
* @throws ValidationException
*/
public function __construct(array $config = [])
{
if (!isset($config['transportConfig']['grpc']['stubOpts'])) {
// Workaround for large messages.
$config['transportConfig']['grpc']['stubOpts'] = [
'grpc.max_send_message_length' => -1,
'grpc.max_receive_message_length' => -1
];
}

$this->projectId = $this->detectProjectId($config);
$this->gapicClient = new GapicClient($config);
}

/**
* Returns a table instance which can be used to read rows and to perform
* insert, update, and delete operations.
*
* Example:
* ```
* $table = $bigtable->table('my-instance', 'my-table');
* ```
*
* @param string $instanceId The instance ID.
* @param string $tableId The table ID.
* @param array $options [optional] {
* Configuration options.
*
* @type string $appProfileId This value specifies routing for
* replication. **Defaults to** the "default" application profile.
* @type array $headers Headers to be passed with each request.
* }
* @return Table
*/
public function table($instanceId, $tableId, array $options = [])
{
return new Table(
$this->gapicClient,
GapicClient::tableName($this->projectId, $instanceId, $tableId),
$options
);
}
}
7 changes: 4 additions & 3 deletions Bigtable/src/ChunkFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
*
* Example:
* ```
* use Google\Cloud\Bigtable\DataClient;
* use Google\Cloud\Bigtable\BigtableClient;
*
* $dataClient = new DataClient('my-instance', 'my-table');
* $formatter = $dataClient->readRows();
* $bigtable = new BigtableClient();
* $table = $bigtable->table('my-instance', 'my-table');
* $formatter = $table->readRows();
* ```
*/
class ChunkFormatter implements \IteratorAggregate
Expand Down
11 changes: 6 additions & 5 deletions Bigtable/src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
/**
* This class houses static factory methods which can be used to create a
* hierarchy of filters for use with
* {@see Google\Cloud\Bigtable\DataClient::checkAndMutateRow()} or
* {@see Google\Cloud\Bigtable\DataClient::readRows()}.
* {@see Google\Cloud\Bigtable\Table::checkAndMutateRow()} or
* {@see Google\Cloud\Bigtable\Table::readRows()}.
*
* Filters are used to take an input row and produce an alternate view of the
* row based on the specified rules. For example, a filter might trim down a row
Expand Down Expand Up @@ -68,15 +68,16 @@
*
* Example:
* ```
* use Google\Cloud\Bigtable\DataClient;
* use Google\Cloud\Bigtable\BigtableClient;
* use Google\Cloud\Bigtable\Filter;
*
* $dataClient = new DataClient('my-instance', 'my-table');
* $bigtable = new BigtableClient();
* $table = $bigtable->table('my-instance', 'my-table');
* $rowFilter = Filter::chain()
* ->addFilter(Filter::qualifier()->regex('prefix.*'))
* ->addFilter(Filter::limit()->cellsPerRow(10));
*
* $rows = $dataClient->readRows([
* $rows = $table->readRows([
* 'filter' => $rowFilter
* ]);
*
Expand Down
9 changes: 5 additions & 4 deletions Bigtable/src/ReadModifyWriteRowRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
use Google\Cloud\Bigtable\V2\ReadModifyWriteRule;

/**
* This is a builder class which builds read/modify/write rules specifying how the specified rows contents
* are to be transformed into writes. Entries are applied in order, meaning that earlier rules will
* affect the results of later ones. This is intended to be used in combination with
* {@see Google\Cloud\Bigtable\DataClient::readModifyWriteRow()}.
* This is a builder class which builds read/modify/write rules specifying how
* the specified rows contents are to be transformed into writes. Entries are
* applied in order, meaning that earlier rules will affect the results of later
* ones. This is intended to be used in combination with
* {@see Google\Cloud\Bigtable\Table::readModifyWriteRow()}.
*/
class ReadModifyWriteRowRules
{
Expand Down
Loading