Skip to content

Cloud Bigtable Region tag consistency #2018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions bigtable/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
"""

import argparse
# [START dependencies]
# [START bigtable_hw_imports]
import datetime

from google.cloud import bigtable
from google.cloud.bigtable import column_family
from google.cloud.bigtable import row_filters
# [END dependencies]
# [END bigtable_hw_imports]


def main(project_id, instance_id, table_id):
# [START connecting_to_bigtable]
# [START bigtable_hw_connect]
# The client must be created with admin=True because it will create a
# table.
client = bigtable.Client(project=project_id, admin=True)
instance = client.instance(instance_id)
# [END connecting_to_bigtable]
# [END bigtable_hw_connect]

# [START creating_a_table]
# [START bigtable_hw_create_table]
print('Creating the {} table.'.format(table_id))
table = instance.table(table_id)

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

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

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

# [START getting_a_row]
# [START bigtable_hw_get_with_filter]
print('Getting a single greeting by row key.')
key = 'greeting0'.encode()

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

# [START scanning_all_rows]
# [START bigtable_hw_scan_with_filter]
print('Scanning for all greetings:')
partial_rows = table.read_rows(filter_=row_filter)

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

# [START deleting_a_table]
# [START bigtable_hw_delete_table]
print('Deleting the {} table.'.format(table_id))
table.delete()
# [END deleting_a_table]
# [END bigtable_hw_delete_table]


if __name__ == '__main__':
Expand Down
27 changes: 14 additions & 13 deletions bigtable/hello_happybase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,33 @@
"""

import argparse

# [START bigtable_hw_imports_happybase]
from google.cloud import bigtable
from google.cloud import happybase
# [END bigtable_hw_imports_happybase]


def main(project_id, instance_id, table_name):
# [START connecting_to_bigtable]
# [START bigtable_hw_connect_happybase]
# The client must be created with admin=True because it will create a
# table.
client = bigtable.Client(project=project_id, admin=True)
instance = client.instance(instance_id)
connection = happybase.Connection(instance=instance)
# [END connecting_to_bigtable]
# [END bigtable_hw_connect_happybase]

try:
# [START creating_a_table]
# [START bigtable_hw_create_table_happybase]
print('Creating the {} table.'.format(table_name))
column_family_name = 'cf1'
connection.create_table(
table_name,
{
column_family_name: dict() # Use default options.
})
# [END creating_a_table]
# [END bigtable_hw_create_table_happybase]

# [START writing_rows]
# [START bigtable_hw_write_rows_happybase]
print('Writing some greetings to the table.')
table = connection.table(table_name)
column_name = '{fam}:greeting'.format(fam=column_family_name)
Expand All @@ -75,26 +76,26 @@ def main(project_id, instance_id, table_name):
table.put(
row_key, {column_name.encode('utf-8'): value.encode('utf-8')}
)
# [END writing_rows]
# [END bigtable_hw_write_rows_happybase]

# [START getting_a_row]
# [START bigtable_hw_get_by_key_happybase]
print('Getting a single greeting by row key.')
key = 'greeting0'.encode('utf-8')
row = table.row(key)
print('\t{}: {}'.format(key, row[column_name.encode('utf-8')]))
# [END getting_a_row]
# [END bigtable_hw_get_by_key_happybase]

# [START scanning_all_rows]
# [START bigtable_hw_scan_all_happybase]
print('Scanning for all greetings:')

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

# [START deleting_a_table]
# [START bigtable_hw_delete_table_happybase]
print('Deleting the {} table.'.format(table_name))
connection.delete_table(table_name)
# [END deleting_a_table]
# [END bigtable_hw_delete_table_happybase]

finally:
connection.close()
Expand Down