the GCloud BigTable example

this illustrates how you can create a google big table. It is important to understand that many of the "create" operators are asynchronous. What this means that it may take some time for them to complete even though the function call has returned. if you get an exception, just wait a minute and try again. we could put a loop with try block and a sleep around each one of these blocks, but there must be an easier way.

In [1]:
from gcloud import bigtable
clientbt = bigtable.Client(admin=True)
clientbt.start()
In [3]:
instance = clientbt.instance('cloud-book-instance')
table = instance.table('book-table2')
table.create()
In [4]:
column_family = table.column_family('cf')
column_family.create()
In [5]:
row= table.row('key1')
row.set_cell('cf', 'experiment', 'exp1')
row.set_cell('cf', 'date', '6/6/16')
row.set_cell('cf', 'link', 'http://some_location')
row.commit()
In [6]:
row= table.row('key2')
row.set_cell('cf', 'experiment', 'exp2')
row.set_cell('cf', 'date', '6/7/16')
row.set_cell('cf', 'link', 'http://some_other_location')
row.commit()
In [7]:
row= table.row('key3')
row.set_cell('cf', 'experiment', 'exp3')
row.set_cell('cf', 'date', '6/11/16')
row.set_cell('cf', 'link', 'http://a_good_location')
row.commit()
In [8]:
keys = ['key1', 'key2', 'key3']
In [13]:
colnames = ['experiment', 'date', 'link']
for key in keys:
    row_data = table.read_row(key) 
    cells = row_data.cells['cf']
    vals = [ cells[name][0].value for name in colnames]
    print vals
['exp1', '6/6/16', 'http://some_location']
['exp2', '6/7/16', 'http://some_other_location']
['exp3', '6/11/16', 'http://a_good_location']
In [ ]: