Skip to content

Commit

Permalink
Implementing Table.update_column_family().
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 28, 2015
1 parent f3460ce commit a8a7f25
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 50 deletions.
30 changes: 30 additions & 0 deletions gcloud_bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,33 @@ def create_column_family(self, column_family_id, gc_rule=None,
timeout_seconds)
# We expect a `._generated.bigtable_table_data_pb2.ColumnFamily`
response.result()

def update_column_family(self, column_family_id, gc_rule=None,
timeout_seconds=TIMEOUT_SECONDS):
"""Update a column family in this table.
:type column_family_id: string
:param column_family_id: The ID of the column family.
:type gc_rule: :class:`GarbageCollectionRule`,
:class:`GarbageCollectionRuleUnion` or
:class:`GarbageCollectionRuleIntersection`
:param gc_rule: The garbage collection settings for the column family.
:type timeout_seconds: integer
:param timeout_seconds: Number of seconds for request time-out.
If not passed, defaults to ``TIMEOUT_SECONDS``.
"""
column_family_name = self.name + '/columnFamilies/' + column_family_id
request_kwargs = {'name': column_family_name}
if gc_rule is not None:
request_kwargs['gc_rule'] = gc_rule.to_pb()
request_pb = data_pb2.ColumnFamily(**request_kwargs)

stub = make_stub(self.credentials, TABLE_STUB_FACTORY,
TABLE_ADMIN_HOST, TABLE_ADMIN_PORT)
with stub:
response = stub.UpdateColumnFamily.async(request_pb,
timeout_seconds)
# We expect a `._generated.bigtable_table_data_pb2.ColumnFamily`
response.result()
38 changes: 0 additions & 38 deletions gcloud_bigtable/table_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,6 @@ class TableConnection(Connection):
SCOPE = 'https://www.googleapis.com/auth/cloud-bigtable.admin'
"""Scope for Table Admin and Cluster Admin API requests."""

def update_column_family(self, cluster_name, table_id, column_family_id,
timeout_seconds=TIMEOUT_SECONDS):
"""Update an existing column family in a table.
.. note::
As in :meth:`create_column_family`, we don't currently support
setting
* ``gc_expression``
* ``gc_rule``
As a result, there is nothing else to be changed in this method.
:type cluster_name: string
:param cluster_name: The name of the cluster where the column family
will be updated. Must be of the form
"projects/../zones/../clusters/.."
Since this is a low-level class, we don't check
this, rather we expect callers to pass correctly
formatted data.
:type table_id: string
:param table_id: The name of the table within the cluster.
:type column_family_id: string
:param column_family_id: The name of the column family within
the table.
:type timeout_seconds: integer
:param timeout_seconds: Number of seconds for request time-out.
If not passed, defaults to ``TIMEOUT_SECONDS``.
:raises: :class:`NotImplementedError`
"""
raise NotImplementedError('UpdateColumnFamily is not currently '
'supported due to lack of support for '
'garbage colection settings.')

def delete_column_family(self, cluster_name, table_id, column_family_id,
timeout_seconds=TIMEOUT_SECONDS):
"""Delete an existing column family in a table.
Expand Down
46 changes: 46 additions & 0 deletions gcloud_bigtable/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,52 @@ def test_create_column_family_with_gc_rule(self):
gc_rule = GarbageCollectionRule(max_num_versions=1337)
self._create_column_family_test_helper(gc_rule=gc_rule)

def _update_column_family_test_helper(self, gc_rule=None):
from gcloud_bigtable._generated import (
bigtable_table_data_pb2 as data_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)
if gc_rule is None:
request_pb = data_pb2.ColumnFamily(name=column_family_name)
else:
request_pb = data_pb2.ColumnFamily(
name=column_family_name,
gc_rule=gc_rule.to_pb(),
)

# Create response_pb
response_pb = data_pb2.ColumnFamily()

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

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

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

self._grpc_client_test_helper('UpdateColumnFamily', result_method,
request_pb, response_pb, expected_result,
PROJECT_ID)

def test_update_column_family(self):
self._update_column_family_test_helper(gc_rule=None)

def test_update_column_family_with_gc_rule(self):
from gcloud_bigtable.table import GarbageCollectionRule
gc_rule = GarbageCollectionRule(max_num_versions=1337)
self._update_column_family_test_helper(gc_rule=gc_rule)


class _Cluster(object):

Expand Down
12 changes: 0 additions & 12 deletions gcloud_bigtable/test_table_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ def test_constructor(self):
('create_scoped', ((klass.SCOPE,),), {}),
])

def test_update_column_family(self):
from gcloud_bigtable._testing import _MockWithAttachedMethods

credentials = _MockWithAttachedMethods(False)
connection = self._makeOne(credentials=credentials)
self.assertEqual(credentials._called, [
('create_scoped_required', (), {}),
])

self.assertRaises(NotImplementedError, connection.update_column_family,
CLUSTER_NAME, TABLE_ID, COLUMN_FAMILY_ID)

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

0 comments on commit a8a7f25

Please sign in to comment.