Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9396eb5

Browse filesBrowse files
Cloud Bigtable Region tag consistency (GoogleCloudPlatform#2018)
* Updating the region tags to be consistent across Cloud Bigtable. Need to figure out filtering for happybase or rename * Remove happybase filter * Linting
1 parent b3fee0a commit 9396eb5
Copy full SHA for 9396eb5

File tree

Expand file treeCollapse file tree

2 files changed

+30
-29
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-29
lines changed

‎bigtable/hello/main.py

Copy file name to clipboardExpand all lines: bigtable/hello/main.py
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@
2525
"""
2626

2727
import argparse
28-
# [START dependencies]
28+
# [START bigtable_hw_imports]
2929
import datetime
3030

3131
from google.cloud import bigtable
3232
from google.cloud.bigtable import column_family
3333
from google.cloud.bigtable import row_filters
34-
# [END dependencies]
34+
# [END bigtable_hw_imports]
3535

3636

3737
def main(project_id, instance_id, table_id):
38-
# [START connecting_to_bigtable]
38+
# [START bigtable_hw_connect]
3939
# The client must be created with admin=True because it will create a
4040
# table.
4141
client = bigtable.Client(project=project_id, admin=True)
4242
instance = client.instance(instance_id)
43-
# [END connecting_to_bigtable]
43+
# [END bigtable_hw_connect]
4444

45-
# [START creating_a_table]
45+
# [START bigtable_hw_create_table]
4646
print('Creating the {} table.'.format(table_id))
4747
table = instance.table(table_id)
4848

@@ -56,9 +56,9 @@ def main(project_id, instance_id, table_id):
5656
table.create(column_families=column_families)
5757
else:
5858
print("Table {} already exists.".format(table_id))
59-
# [END creating_a_table]
59+
# [END bigtable_hw_create_table]
6060

61-
# [START writing_rows]
61+
# [START bigtable_hw_write_rows]
6262
print('Writing some greetings to the table.')
6363
greetings = ['Hello World!', 'Hello Cloud Bigtable!', 'Hello Python!']
6464
rows = []
@@ -82,36 +82,36 @@ def main(project_id, instance_id, table_id):
8282
timestamp=datetime.datetime.utcnow())
8383
rows.append(row)
8484
table.mutate_rows(rows)
85-
# [END writing_rows]
85+
# [END bigtable_hw_write_rows]
8686

87-
# [START creating_a_filter]
87+
# [START bigtable_hw_create_filter]
8888
# Create a filter to only retrieve the most recent version of the cell
8989
# for each column accross entire row.
9090
row_filter = row_filters.CellsColumnLimitFilter(1)
91-
# [END creating_a_filter]
91+
# [END bigtable_hw_create_filter]
9292

93-
# [START getting_a_row]
93+
# [START bigtable_hw_get_with_filter]
9494
print('Getting a single greeting by row key.')
9595
key = 'greeting0'.encode()
9696

9797
row = table.read_row(key, row_filter)
9898
cell = row.cells[column_family_id][column][0]
9999
print(cell.value.decode('utf-8'))
100-
# [END getting_a_row]
100+
# [END bigtable_hw_get_with_filter]
101101

102-
# [START scanning_all_rows]
102+
# [START bigtable_hw_scan_with_filter]
103103
print('Scanning for all greetings:')
104104
partial_rows = table.read_rows(filter_=row_filter)
105105

106106
for row in partial_rows:
107107
cell = row.cells[column_family_id][column][0]
108108
print(cell.value.decode('utf-8'))
109-
# [END scanning_all_rows]
109+
# [END bigtable_hw_scan_with_filter]
110110

111-
# [START deleting_a_table]
111+
# [START bigtable_hw_delete_table]
112112
print('Deleting the {} table.'.format(table_id))
113113
table.delete()
114-
# [END deleting_a_table]
114+
# [END bigtable_hw_delete_table]
115115

116116

117117
if __name__ == '__main__':

‎bigtable/hello_happybase/main.py

Copy file name to clipboardExpand all lines: bigtable/hello_happybase/main.py
+14-13Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,33 @@
2525
"""
2626

2727
import argparse
28-
28+
# [START bigtable_hw_imports_happybase]
2929
from google.cloud import bigtable
3030
from google.cloud import happybase
31+
# [END bigtable_hw_imports_happybase]
3132

3233

3334
def main(project_id, instance_id, table_name):
34-
# [START connecting_to_bigtable]
35+
# [START bigtable_hw_connect_happybase]
3536
# The client must be created with admin=True because it will create a
3637
# table.
3738
client = bigtable.Client(project=project_id, admin=True)
3839
instance = client.instance(instance_id)
3940
connection = happybase.Connection(instance=instance)
40-
# [END connecting_to_bigtable]
41+
# [END bigtable_hw_connect_happybase]
4142

4243
try:
43-
# [START creating_a_table]
44+
# [START bigtable_hw_create_table_happybase]
4445
print('Creating the {} table.'.format(table_name))
4546
column_family_name = 'cf1'
4647
connection.create_table(
4748
table_name,
4849
{
4950
column_family_name: dict() # Use default options.
5051
})
51-
# [END creating_a_table]
52+
# [END bigtable_hw_create_table_happybase]
5253

53-
# [START writing_rows]
54+
# [START bigtable_hw_write_rows_happybase]
5455
print('Writing some greetings to the table.')
5556
table = connection.table(table_name)
5657
column_name = '{fam}:greeting'.format(fam=column_family_name)
@@ -75,26 +76,26 @@ def main(project_id, instance_id, table_name):
7576
table.put(
7677
row_key, {column_name.encode('utf-8'): value.encode('utf-8')}
7778
)
78-
# [END writing_rows]
79+
# [END bigtable_hw_write_rows_happybase]
7980

80-
# [START getting_a_row]
81+
# [START bigtable_hw_get_by_key_happybase]
8182
print('Getting a single greeting by row key.')
8283
key = 'greeting0'.encode('utf-8')
8384
row = table.row(key)
8485
print('\t{}: {}'.format(key, row[column_name.encode('utf-8')]))
85-
# [END getting_a_row]
86+
# [END bigtable_hw_get_by_key_happybase]
8687

87-
# [START scanning_all_rows]
88+
# [START bigtable_hw_scan_all_happybase]
8889
print('Scanning for all greetings:')
8990

9091
for key, row in table.scan():
9192
print('\t{}: {}'.format(key, row[column_name.encode('utf-8')]))
92-
# [END scanning_all_rows]
93+
# [END bigtable_hw_scan_all_happybase]
9394

94-
# [START deleting_a_table]
95+
# [START bigtable_hw_delete_table_happybase]
9596
print('Deleting the {} table.'.format(table_name))
9697
connection.delete_table(table_name)
97-
# [END deleting_a_table]
98+
# [END bigtable_hw_delete_table_happybase]
9899

99100
finally:
100101
connection.close()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.