Skip to content
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

Adding HappyBase Table.counter_set(). #1541

Merged
merged 1 commit into from
Feb 29, 2016
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
24 changes: 24 additions & 0 deletions gcloud/bigtable/happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,30 @@ def counter_get(self, row, column):
# is correctly initialized if didn't exist yet.
return self.counter_inc(row, column, value=0)

def counter_set(self, row, column, value=0):
"""Set a counter column to a specific value.

This method is provided in HappyBase, but we do not provide it here
because it defeats the purpose of using atomic increment and decrement
of a counter.

:type row: str
:param row: Row key for the row we are setting a counter in.

:type column: str
:param column: Column we are setting a value in; of
the form ``fam:col``.

:type value: int
:param value: Value to set the counter to.

:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
always
"""
raise NotImplementedError('Table.counter_set will not be implemented. '
'Instead use the increment/decrement '
'methods along with counter_get.')

def counter_inc(self, row, column, value=1):
"""Atomically increment a counter column.

Expand Down
11 changes: 11 additions & 0 deletions gcloud/bigtable/happybase/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ def _counter_inc_helper(self, row, column, value, commit_result):
self.assertEqual(row_obj.counts,
{tuple(column.split(':')): incremented_value})

def test_counter_set(self):
name = 'table-name'
connection = None
table = self._makeOne(name, connection)

row = 'row-key'
column = 'fam:col1'
value = 42
with self.assertRaises(NotImplementedError):
table.counter_set(row, column, value=value)

def test_counter_inc(self):
import struct

Expand Down