Skip to content

Making bigtable tests run successfully #1764

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 5 commits into from
Oct 16, 2018
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
6 changes: 3 additions & 3 deletions bigtable/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions bigtable/tableadmin/tableadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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...')
Expand Down
2 changes: 2 additions & 0 deletions bigtable/tableadmin/tableadmin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import random

from tableadmin import create_table
from tableadmin import delete_table
from tableadmin import run_table_operations

Expand Down Expand Up @@ -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()
Expand Down