25
25
"""
26
26
27
27
import argparse
28
- # [START dependencies ]
28
+ # [START bigtable_hw_imports ]
29
29
import datetime
30
30
31
31
from google .cloud import bigtable
32
32
from google .cloud .bigtable import column_family
33
33
from google .cloud .bigtable import row_filters
34
- # [END dependencies ]
34
+ # [END bigtable_hw_imports ]
35
35
36
36
37
37
def main (project_id , instance_id , table_id ):
38
- # [START connecting_to_bigtable ]
38
+ # [START bigtable_hw_connect ]
39
39
# The client must be created with admin=True because it will create a
40
40
# table.
41
41
client = bigtable .Client (project = project_id , admin = True )
42
42
instance = client .instance (instance_id )
43
- # [END connecting_to_bigtable ]
43
+ # [END bigtable_hw_connect ]
44
44
45
- # [START creating_a_table ]
45
+ # [START bigtable_hw_create_table ]
46
46
print ('Creating the {} table.' .format (table_id ))
47
47
table = instance .table (table_id )
48
48
@@ -56,9 +56,9 @@ def main(project_id, instance_id, table_id):
56
56
table .create (column_families = column_families )
57
57
else :
58
58
print ("Table {} already exists." .format (table_id ))
59
- # [END creating_a_table ]
59
+ # [END bigtable_hw_create_table ]
60
60
61
- # [START writing_rows ]
61
+ # [START bigtable_hw_write_rows ]
62
62
print ('Writing some greetings to the table.' )
63
63
greetings = ['Hello World!' , 'Hello Cloud Bigtable!' , 'Hello Python!' ]
64
64
rows = []
@@ -82,36 +82,36 @@ def main(project_id, instance_id, table_id):
82
82
timestamp = datetime .datetime .utcnow ())
83
83
rows .append (row )
84
84
table .mutate_rows (rows )
85
- # [END writing_rows ]
85
+ # [END bigtable_hw_write_rows ]
86
86
87
- # [START creating_a_filter ]
87
+ # [START bigtable_hw_create_filter ]
88
88
# Create a filter to only retrieve the most recent version of the cell
89
89
# for each column accross entire row.
90
90
row_filter = row_filters .CellsColumnLimitFilter (1 )
91
- # [END creating_a_filter ]
91
+ # [END bigtable_hw_create_filter ]
92
92
93
- # [START getting_a_row ]
93
+ # [START bigtable_hw_get_with_filter ]
94
94
print ('Getting a single greeting by row key.' )
95
95
key = 'greeting0' .encode ()
96
96
97
97
row = table .read_row (key , row_filter )
98
98
cell = row .cells [column_family_id ][column ][0 ]
99
99
print (cell .value .decode ('utf-8' ))
100
- # [END getting_a_row ]
100
+ # [END bigtable_hw_get_with_filter ]
101
101
102
- # [START scanning_all_rows ]
102
+ # [START bigtable_hw_scan_with_filter ]
103
103
print ('Scanning for all greetings:' )
104
104
partial_rows = table .read_rows (filter_ = row_filter )
105
105
106
106
for row in partial_rows :
107
107
cell = row .cells [column_family_id ][column ][0 ]
108
108
print (cell .value .decode ('utf-8' ))
109
- # [END scanning_all_rows ]
109
+ # [END bigtable_hw_scan_with_filter ]
110
110
111
- # [START deleting_a_table ]
111
+ # [START bigtable_hw_delete_table ]
112
112
print ('Deleting the {} table.' .format (table_id ))
113
113
table .delete ()
114
- # [END deleting_a_table ]
114
+ # [END bigtable_hw_delete_table ]
115
115
116
116
117
117
if __name__ == '__main__' :
0 commit comments