2525"""
2626
2727import argparse
28+ import datetime
2829
2930from gcloud import bigtable
31+ from gcloud .bigtable import row_filters
3032
3133
3234def main (project_id , instance_id , table_id ):
@@ -40,6 +42,11 @@ def main(project_id, instance_id, table_id):
4042 # [START creating_a_table]
4143 print ('Creating the {} table.' .format (table_id ))
4244 table = instance .table (table_id )
45+ try :
46+ table .delete ()
47+ except Exception :
48+ pass
49+
4350 table .create ()
4451 column_family_id = 'cf1'
4552 cf1 = table .column_family (column_family_id )
@@ -73,14 +80,26 @@ def main(project_id, instance_id, table_id):
7380 column_id ,
7481 value .encode ('utf-8' ))
7582 row .commit ()
83+
84+ # Now commit an older version
85+ row = table .row (row_key )
86+ myts = datetime .datetime .utcfromtimestamp (200.0 / 1000000 )
87+ row .set_cell (
88+ column_family_id , column_id , value .encode ('utf-8' ), timestamp = myts )
89+ row .commit ()
7690 # [END writing_rows]
7791
7892 # [START getting_a_row]
7993 print ('Getting a single greeting by row key.' )
8094 key = 'greeting0'
81- row = table .read_row (key .encode ('utf-8' ))
95+ col_filter = row_filters .ColumnQualifierRegexFilter (column_id )
96+ family_filter = row_filters .FamilyNameRegexFilter (column_family_id )
97+ row_filter = row_filters .RowFilterUnion (filters = [col_filter , family_filter ])
98+ row = table .read_row (key .encode ('utf-8' ), filter_ = row_filter )
8299 value = row .cells [column_family_id ][column_id ][0 ].value
83- print ('\t {}: {}' .format (key , value .decode ('utf-8' )))
100+ timestamp = row .cells [column_family_id ][column_id ][0 ].timestamp
101+ print ('\t {}: {} {}' .format (key , value .decode ('utf-8' ), timestamp ))
102+
84103 # [END getting_a_row]
85104
86105 # [START scanning_all_rows]
0 commit comments