Skip to content

Commit

Permalink
Merge pull request #1541 from dhermes/happybase-counter-set
Browse files Browse the repository at this point in the history
Adding HappyBase Table.counter_set().
  • Loading branch information
dhermes committed Feb 29, 2016
2 parents 43674b9 + cdcc1a8 commit 2ab8edc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gcloud/bigtable/happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,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 @@ -886,6 +886,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

0 comments on commit 2ab8edc

Please sign in to comment.