Skip to content

Commit 5dfa97f

Browse files
Merge pull request GoogleCloudPlatform#851 from GoogleCloudPlatform/bigtable-read-samples
Bigtable read/write samples + quickstart
2 parents 86eeac3 + 201a3ba commit 5dfa97f

28 files changed

+533
-41
lines changed
File renamed without changes.

bigtable/api/composer.json renamed to bigtable/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"google/cloud-bigtable": "^0.9.1"
3+
"google/cloud-bigtable": "^0.10.1"
44
},
55
"require-dev": {
66
"google/cloud-tools": "^0.8",

bigtable/api/phpunit.xml.dist renamed to bigtable/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
xml version="1.0" encoding="UTF-8"?>
22
bigtable/api/src/create_cluster.php renamed to bigtable/src/create_cluster.php
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_dev_instance.php renamed to bigtable/src/create_dev_instance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_family_gc_intersection.php renamed to bigtable/src/create_family_gc_intersection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_family_gc_max_age.php renamed to bigtable/src/create_family_gc_max_age.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_family_gc_max_versions.php renamed to bigtable/src/create_family_gc_max_versions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_family_gc_nested.php renamed to bigtable/src/create_family_gc_nested.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_family_gc_union.php renamed to bigtable/src/create_family_gc_union.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_production_instance.php renamed to bigtable/src/create_production_instance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/create_table.php renamed to bigtable/src/create_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/delete_cluster.php renamed to bigtable/src/delete_cluster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/delete_family.php renamed to bigtable/src/delete_family.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/delete_instance.php renamed to bigtable/src/delete_instance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer

bigtable/api/src/delete_table.php renamed to bigtable/src/delete_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
22

33
/**
4-
* Copyright 2018 Google LLC.
4+
* Copyright 2019 Google LLC.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
/**
2020
* For instructions on how to run the full sample:
2121
*
22-
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/api/README.md
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
2323
*/
2424

2525
// Include Google Cloud dependendencies using Composer
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
3+
/**
4+
* Copyright 2019 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the full sample:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
23+
*/
24+
25+
// Include Google Cloud dependendencies using Composer
26+
require_once __DIR__ . '/../../vendor/autoload.php';
27+
28+
if (count($argv) != 4) {
29+
return printf("Usage: php %s PROJECT_ID INSTANCE_ID TABLE_ID" . PHP_EOL, __FILE__);
30+
}
31+
list($_, $project_id, $instance_id, $table_id) = $argv;
32+
33+
// [START bigtable_hw_create_table]
34+
35+
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
36+
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
37+
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
38+
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
39+
use Google\Cloud\Bigtable\Admin\V2\Table\View;
40+
use Google\Cloud\Bigtable\Admin\V2\Table;
41+
use Google\ApiCore\ApiException;
42+
43+
/** Uncomment and populate these variables in your code */
44+
// $project_id = 'The Google project ID';
45+
// $instance_id = 'The Bigtable instance ID';
46+
// $table_id = 'The Bigtable table ID';
47+
48+
$instanceAdminClient = new BigtableInstanceAdminClient();
49+
$tableAdminClient = new BigtableTableAdminClient();
50+
51+
$instanceName = $instanceAdminClient->instanceName($project_id, $instance_id);
52+
$tableName = $tableAdminClient->tableName($project_id, $instance_id, $table_id);
53+
54+
// Check whether table exists in an instance.
55+
// Create table if it does not exists.
56+
$table = new Table();
57+
printf('Creating a Table : %s' . PHP_EOL, $table_id);
58+
59+
try {
60+
$tableAdminClient->getTable($tableName, ['view' => View::NAME_ONLY]);
61+
printf('Table %s alredy exists' . PHP_EOL, $table_id);
62+
} catch (ApiException $e) {
63+
if ($e->getStatus() === 'NOT_FOUND') {
64+
printf('Creating the %s table' . PHP_EOL, $table_id);
65+
66+
$tableAdminClient->createtable(
67+
$instanceName,
68+
$table_id,
69+
$table
70+
);
71+
$columnFamily = new ColumnFamily();
72+
$columnModification = new Modification();
73+
$columnModification->setId('cf1');
74+
$columnModification->setCreate($columnFamily);
75+
$tableAdminClient->modifyColumnFamilies($tableName, [$columnModification]);
76+
printf('Created table %s' . PHP_EOL, $table_id);
77+
} else {
78+
throw $e;
79+
}
80+
}
81+
// [END bigtable_hw_create_table]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
3+
/**
4+
* Copyright 2019 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the full sample:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/bigtable/README.md
23+
*/
24+
25+
// Include Google Cloud dependendencies using Composer
26+
require_once __DIR__ . '/../../vendor/autoload.php';
27+
28+
if (count($argv) < 3 || count($argv) > 5) {
29+
return printf("Usage: php %s PROJECT_ID INSTANCE_ID TABLE_ID" . PHP_EOL, __FILE__);
30+
}
31+
list($_, $project_id, $instance_id, $table_id) = $argv;
32+
33+
// [START bigtable_hw_get_with_filter]
34+
35+
use Google\Cloud\Bigtable\BigtableClient;
36+
use Google\Cloud\Bigtable\V2\RowFilter;
37+
38+
/** Uncomment and populate these variables in your code */
39+
// $project_id = 'The Google project ID';
40+
// $instance_id = 'The Bigtable instance ID';
41+
// $table_id = 'The Bigtable table ID';
42+
43+
44+
// Connect to an existing table with an existing instance.
45+
$dataClient = new BigtableClient([
46+
'projectId' => $project_id,
47+
]);
48+
$table = $dataClient->table($instance_id, $table_id);
49+
50+
printf('Getting a single greeting by row key.' . PHP_EOL);
51+
$key = 'greeting0';
52+
// Only retrieve the most recent version of the cell.
53+
$row_filter = (new RowFilter)->setCellsPerColumnLimitFilter(1);
54+
55+
$column = 'greeting';
56+
$columnFamilyId = 'cf1';
57+
58+
$row = $table->readRow($key, [
59+
'rowFilter' => $row_filter
60+
]);
61+
printf('%s' . PHP_EOL, $row[$columnFamilyId][$column][0]['value']);
62+
// [END bigtable_hw_get_with_filter]

0 commit comments

Comments
 (0)