Skip to content

Commit

Permalink
Moving delete_column_family from Table to ColumnFamily.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 29, 2015
1 parent 949e783 commit b93c8c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 58 deletions.
18 changes: 18 additions & 0 deletions gcloud_bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ColumnFamily(object):
* :meth:`create` itself
* :meth:`update` itself
* :meth:`delete` itself
:type column_family_id: string
:param column_family_id: The ID of the column family.
Expand Down Expand Up @@ -246,3 +247,20 @@ def update(self, timeout_seconds=None):
timeout_seconds)
# We expect a `data_pb2.ColumnFamily`
response.result()

def delete(self, timeout_seconds=None):
"""Delete this column family.
:type timeout_seconds: integer
:param timeout_seconds: Number of seconds for request time-out.
If not passed, defaults to value set on table.
"""
request_pb = messages_pb2.DeleteColumnFamilyRequest(name=self.name)
stub = make_stub(self.client, TABLE_STUB_FACTORY,
TABLE_ADMIN_HOST, TABLE_ADMIN_PORT)
with stub:
timeout_seconds = timeout_seconds or self.timeout_seconds
response = stub.DeleteColumnFamily.async(request_pb,
timeout_seconds)
# We expect a `._generated.empty_pb2.Empty`
response.result()
22 changes: 0 additions & 22 deletions gcloud_bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,3 @@ def delete(self, timeout_seconds=None):
response = stub.DeleteTable.async(request_pb, timeout_seconds)
# We expect a `._generated.empty_pb2.Empty`
response.result()

def delete_column_family(self, column_family_id, timeout_seconds=None):
"""Delete a column family in this table.
:type column_family_id: string
:param column_family_id: The ID of the column family.
:type timeout_seconds: integer
:param timeout_seconds: Number of seconds for request time-out.
If not passed, defaults to value set on table.
"""
column_family_name = self.name + '/columnFamilies/' + column_family_id
request_pb = messages_pb2.DeleteColumnFamilyRequest(
name=column_family_name)
stub = make_stub(self.client, TABLE_STUB_FACTORY,
TABLE_ADMIN_HOST, TABLE_ADMIN_PORT)
with stub:
timeout_seconds = timeout_seconds or self.timeout_seconds
response = stub.DeleteColumnFamily.async(request_pb,
timeout_seconds)
# We expect a `._generated.empty_pb2.Empty`
response.result()
35 changes: 35 additions & 0 deletions gcloud_bigtable/test_column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,41 @@ def test_update_with_gc_rule(self):
gc_rule = GarbageCollectionRule(max_num_versions=1337)
self._update_test_helper(gc_rule=gc_rule)

def test_delete(self):
from gcloud_bigtable._generated import (
bigtable_table_service_messages_pb2 as messages_pb2)
from gcloud_bigtable._generated import empty_pb2

# Create request_pb
column_family_name = (
'projects/' + PROJECT_ID + '/zones/' + ZONE +
'/clusters/' + CLUSTER_ID + '/tables/' + TABLE_ID +
'/columnFamilies/' + COLUMN_FAMILY_ID)
request_pb = messages_pb2.DeleteColumnFamilyRequest(
name=column_family_name)

# Create response_pb
response_pb = empty_pb2.Empty()

# Create expected_result.
expected_result = None # delete() has no return value.

# We must create the cluster with the client passed in
# and then the table with that cluster.
TEST_CASE = self
timeout_seconds = 7

def result_method(client):
cluster = client.cluster(ZONE, CLUSTER_ID)
table = cluster.table(TABLE_ID)
column_family = TEST_CASE._makeOne(COLUMN_FAMILY_ID, table)
return column_family.delete(timeout_seconds=timeout_seconds)

self._grpc_client_test_helper('DeleteColumnFamily', result_method,
request_pb, response_pb, expected_result,
PROJECT_ID,
timeout_seconds=timeout_seconds)


class _Table(object):

Expand Down
36 changes: 0 additions & 36 deletions gcloud_bigtable/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,42 +247,6 @@ def result_method(client):
PROJECT_ID,
timeout_seconds=timeout_seconds)

def test_delete_column_family(self):
from gcloud_bigtable._generated import (
bigtable_table_service_messages_pb2 as messages_pb2)
from gcloud_bigtable._generated import empty_pb2

# Create request_pb
column_family_id = 'column_family_id'
column_family_name = (
'projects/' + PROJECT_ID + '/zones/' + ZONE +
'/clusters/' + CLUSTER_ID + '/tables/' + TABLE_ID +
'/columnFamilies/' + column_family_id)
request_pb = messages_pb2.DeleteColumnFamilyRequest(
name=column_family_name)

# Create response_pb
response_pb = empty_pb2.Empty()

# Create expected_result.
expected_result = None # delete() has no return value.

# We must create the cluster with the client passed in
# and then the table with that cluster.
TEST_CASE = self
timeout_seconds = 7

def result_method(client):
cluster = client.cluster(ZONE, CLUSTER_ID)
table = TEST_CASE._makeOne(TABLE_ID, cluster)
return table.delete_column_family(column_family_id,
timeout_seconds=timeout_seconds)

self._grpc_client_test_helper('DeleteColumnFamily', result_method,
request_pb, response_pb, expected_result,
PROJECT_ID,
timeout_seconds=timeout_seconds)


class _Cluster(object):

Expand Down

0 comments on commit b93c8c0

Please sign in to comment.