diff --git a/bigtable/hello/main.py b/bigtable/hello/main.py index 8bf927d9dc3..95c78e24fb5 100644 --- a/bigtable/hello/main.py +++ b/bigtable/hello/main.py @@ -59,7 +59,7 @@ def main(project_id, instance_id, table_id): print('Writing some greetings to the table.') greetings = ['Hello World!', 'Hello Cloud Bigtable!', 'Hello Python!'] rows = [] - column = 'greeting' + column = 'greeting'.encode() for i, value in enumerate(greetings): # Note: This example uses sequential numeric IDs for simplicity, # but this can result in poor performance in a production @@ -71,7 +71,7 @@ def main(project_id, instance_id, table_id): # the best performance, see the documentation: # # https://cloud.google.com/bigtable/docs/schema-design - row_key = 'greeting{}'.format(i) + row_key = 'greeting{}'.format(i).encode() row = table.row(row_key) row.set_cell(column_family_id, column, @@ -83,7 +83,7 @@ def main(project_id, instance_id, table_id): # [START getting_a_row] print('Getting a single greeting by row key.') - key = 'greeting0' + key = 'greeting0'.encode() # Only retrieve the most recent version of the cell. row_filter = row_filters.CellsColumnLimitFilter(1) diff --git a/bigtable/tableadmin/tableadmin.py b/bigtable/tableadmin/tableadmin.py index 6bad0bebae8..29551a7f390 100644 --- a/bigtable/tableadmin/tableadmin.py +++ b/bigtable/tableadmin/tableadmin.py @@ -37,8 +37,8 @@ from google.cloud.bigtable import column_family -def run_table_operations(project_id, instance_id, table_id): - ''' Create a Bigtable table and perform basic table operations +def create_table(project_id, instance_id, table_id): + ''' Create a Bigtable table :type project_id: str :param project_id: Project id of the client. @@ -64,6 +64,24 @@ def run_table_operations(project_id, instance_id, table_id): table.create() print('Created table {}.'.format(table_id)) + return client, instance, table + + +def run_table_operations(project_id, instance_id, table_id): + ''' Create a Bigtable table and perform basic operations on it + + :type project_id: str + :param project_id: Project id of the client. + + :type instance_id: str + :param instance_id: Instance of the client. + + :type table_id: str + :param table_id: Table id to create table. + ''' + + client, instance, table = create_table(project_id, instance_id, table_id) + # [START bigtable_list_tables] tables = instance.list_tables() print('Listing tables in current project...') diff --git a/bigtable/tableadmin/tableadmin_test.py b/bigtable/tableadmin/tableadmin_test.py index df384a18b80..c5852ed77f2 100755 --- a/bigtable/tableadmin/tableadmin_test.py +++ b/bigtable/tableadmin/tableadmin_test.py @@ -16,6 +16,7 @@ import os import random +from tableadmin import create_table from tableadmin import delete_table from tableadmin import run_table_operations @@ -53,6 +54,7 @@ def test_run_table_operations(capsys): def test_delete_table(capsys): table_name = TABLE_NAME_FORMAT.format( random.randrange(TABLE_NAME_RANGE)) + create_table(PROJECT, BIGTABLE_CLUSTER, table_name) delete_table(PROJECT, BIGTABLE_CLUSTER, table_name) out, _ = capsys.readouterr()