HappyBase happybase.Connection.create_table throws happybase.hbase.ttypes.AlreadyExists when a table already exists.
https://github.com/wbolster/happybase/blob/3565b2b43b377b3e539315570d3e51d053d7a8a1/happybase/Hbase.thrift#L274
In the gcloud-python implementation, this throws an internal gRPC error.
Create table Hello-Bigtable
Traceback (most recent call last):
File "hello.py", line 119, in <module>
main()
File "hello.py", line 95, in main
table = create_table(connection, TABLE_NAME, COLUMN_FAMILY_NAME)
File "hello.py", line 76, in create_table
column_family_name: dict() # Use default options.
File "/usr/local/google/home/swast/venv/bigtable_helloworld/local/lib/python2.7/site-packages/gcloud/bigtable/happybase/connection.py", line 341, in create_table
low_level_table.create()
File "/usr/local/google/home/swast/venv/bigtable_helloworld/local/lib/python2.7/site-packages/gcloud/bigtable/table.py", line 177, in create
client._table_stub.CreateTable(request_pb, client.timeout_seconds)
File "/usr/local/google/home/swast/venv/bigtable_helloworld/local/lib/python2.7/site-packages/grpc/framework/crust/implementations.py", line 75, in __call__
protocol_options, metadata, request)
File "/usr/local/google/home/swast/venv/bigtable_helloworld/local/lib/python2.7/site-packages/grpc/framework/crust/_calls.py", line 109, in blocking_unary_unary
return next(rendezvous)
File "/usr/local/google/home/swast/venv/bigtable_helloworld/local/lib/python2.7/site-packages/grpc/framework/crust/_control.py", line 415, in next
raise self._termination.abortion_error
grpc.framework.interfaces.face.face.NetworkError: NetworkError(code=StatusCode.ALREADY_EXISTS, details="Error while creating table Hello-Bigtable in cluster projects/swast-bigtable-examples/zones/us-central1-c/clusters/my-cluster : Transaction Failed : Cannot re-create existing table: Hello-Bigtable")
I can catch this with the following, but it seems weird to differ from vanilla HappyBase in this way.
from gcloud import bigtable
from gcloud.bigtable import happybase
from grpc.framework.interfaces.face import face as grpcface
TABLE_NAME = 'Hello-Bigtable'
COLUMN_FAMILY_NAME = 'cf1'
def create_table(connection, table_name, column_family_name):
try:
connection.create_table(
table_name,
{
column_family_name: dict() # Use default options.
})
except grpcface.NetworkError as exp:
if exp.code != interfaces.StatusCode.ALREADY_EXISTS:
raise
print("Table already exists.")
return connection.table(table_name)
client = bigtable.Client(project=args.project, admin=True)
with client:
cluster = client.cluster('us-central1-c', 'my-cluster')
cluster.reload()
connection = happybase.Connection(cluster=cluster)
print connection.tables()
print('Create table {0}'.format(TABLE_NAME))
table = create_table(connection, TABLE_NAME, COLUMN_FAMILY_NAME)
HappyBase
happybase.Connection.create_tablethrowshappybase.hbase.ttypes.AlreadyExistswhen a table already exists.https://github.com/wbolster/happybase/blob/3565b2b43b377b3e539315570d3e51d053d7a8a1/happybase/Hbase.thrift#L274
In the gcloud-python implementation, this throws an internal gRPC error.
I can catch this with the following, but it seems weird to differ from vanilla HappyBase in this way.