Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bigtable/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Google BigTable Sample
# Google Bigtable Sample

## Description

All code in the `src` directory demonstrates how to connect to Cloud Bigtable and run some basic operations to create instance, create cluster, delete instance and delete cluster.

## Build and Run
1. **Enable APIs** - [Enable the BigTable API](https://console.cloud.google.com/flows/enableapi?apiid=bigtable)
1. **Enable APIs** - [Enable the Bigtable API](https://console.cloud.google.com/flows/enableapi?apiid=bigtable)
and create a new project or select an existing project.
2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "New Credentials"
and select "Service Account Key". Create a new service account, use the JSON key type, and
Expand Down
5 changes: 3 additions & 2 deletions bigtable/composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"require": {
"google/cloud-bigtable": "^0.12.1"
"google/cloud-bigtable": "^0.12.1",
"psr/cache": "^1.0"
},
"require-dev": {
"google/cloud-tools": "^0.8",
"google/cloud-tools": "dev-master",
"phpunit/phpunit": "^5"
}
}
4 changes: 2 additions & 2 deletions bigtable/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
timeoutForMediumTests="30"
timeoutForLargeTests="120">
<testsuites>
<testsuite name="PHP bigtable Instance test">
<file>./test/bigtableTest.php</file>
<testsuite name="PHP Bigtable tests">
<directory>test</directory>
</testsuite>
</testsuites>
<logging>
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_dev_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_family_gc_intersection.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_family_gc_max_age.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_family_gc_max_versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_family_gc_nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_family_gc_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_production_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/create_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/delete_cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/delete_family.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/delete_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/delete_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/helloworld/create_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/helloworld/get_with_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/helloworld/scan_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/helloworld/write_rows.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/list_column_families.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 4) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/list_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/list_instance_clusters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/list_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) != 3) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/quickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
2 changes: 1 addition & 1 deletion bigtable/src/update_gc_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependendencies using Composer
// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
Expand Down
65 changes: 65 additions & 0 deletions bigtable/src/writes/write_batch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* Copyright 2019 Google LLC.
*
* 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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
return printf("Usage: php %s PROJECT_ID INSTANCE_ID TABLE_ID" . PHP_EOL, __FILE__);
}
list($_, $project_id, $instance_id, $table_id) = $argv;

// [START bigtable_writes_batch]

use Google\Cloud\Bigtable\BigtableClient;
use Google\Cloud\Bigtable\Mutations;

/** Uncomment and populate these variables in your code */
// $project_id = 'The Google project ID';
// $instance_id = 'The Bigtable instance ID';
// $table_id = 'mobile-time-series';

// Connect to an existing table with an existing instance.
$dataClient = new BigtableClient([
'projectId' => $project_id,
]);
$table = $dataClient->table($instance_id, $table_id);

$timestamp = time() * 1000;
$columnFamilyId = 'stats_summary';
$mutations = [
(new Mutations())
->upsert($columnFamilyId, "connected_wifi", 1, $timestamp)
->upsert($columnFamilyId, "os_build", "12155.0.0-rc1", $timestamp),
(new Mutations())
->upsert($columnFamilyId, "connected_wifi", 1, $timestamp)
->upsert($columnFamilyId, "os_build", "12145.0.0-rc6", $timestamp)];

$table->mutateRows([
"tablet#a0b81f74#20190501" => $mutations[0],
"tablet#a0b81f74#20190502" => $mutations[1]]
);

printf('Successfully wrote 2 rows.' . PHP_EOL);
// [END bigtable_writes_batch]
63 changes: 63 additions & 0 deletions bigtable/src/writes/write_conditionally.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* Copyright 2019 Google LLC.
*
* 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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
*/

// Include Google Cloud dependencies using Composer
require_once __DIR__ . '/../../vendor/autoload.php';

if (count($argv) < 3 || count($argv) > 5) {
return printf("Usage: php %s PROJECT_ID INSTANCE_ID TABLE_ID" . PHP_EOL, __FILE__);
}
list($_, $project_id, $instance_id, $table_id) = $argv;

// [START bigtable_writes_conditional]

use Google\Cloud\Bigtable\BigtableClient;
use Google\Cloud\Bigtable\Filter;
use Google\Cloud\Bigtable\Mutations;

/** Uncomment and populate these variables in your code */
// $project_id = 'The Google project ID';
// $instance_id = 'The Bigtable instance ID';
// $table_id = 'mobile-time-series';

// Connect to an existing table with an existing instance.
$dataClient = new BigtableClient([
'projectId' => $project_id,
]);
$table = $dataClient->table($instance_id, $table_id);

$timestamp = time() * 1000;
$columnFamilyId = 'stats_summary';

$mutations = (new Mutations())->upsert($columnFamilyId, "os_name", "android", $timestamp);
$predicateFilter = Filter::chain()
->addFilter(Filter::family()->exactMatch($columnFamilyId))
->addFilter(Filter::qualifier()->exactMatch('os_build'))
->addFilter(Filter::value()->regex('PQ2A.*'));
$options = ['predicateFilter' => $predicateFilter, 'trueMutations' => $mutations];

$table->checkAndMutateRow("phone#4c410523#20190501", $options);

printf('Successfully updated row\'s os_name' . PHP_EOL);
// [END bigtable_writes_conditional]
Loading