Skip to content

Commit

Permalink
Adding all counter_*() methods to HappyBase table.
Browse files Browse the repository at this point in the history
They are just interfaces for now. This completes the public
methods on Table, which also completes the interface for
the entire HappyBase library.
  • Loading branch information
dhermes committed Sep 4, 2015
1 parent d65fd59 commit 2e7837c
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
93 changes: 93 additions & 0 deletions gcloud_bigtable/happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,96 @@ def batch(self, timestamp=None, batch_size=None, transaction=False,
temporarily until the method is implemented.
"""
raise NotImplementedError('Temporarily not implemented.')

def counter_get(self, row, column):
"""Retrieve the current value of a counter column.
This method retrieves the current value of a counter column. If the
counter column does not exist, this function initializes it to ``0``.
.. note::
Application code should **never** store a counter value directly;
use the atomic :meth:`counter_inc` and :meth:`counter_dec` methods
for that.
:type row: str
:param row: Row key for the row we are getting a counter from.
:type column: str
:param column: Column we are ``get``-ing from; of the form ``fam:col``.
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
temporarily until the method is implemented.
"""
raise NotImplementedError('Temporarily not implemented.')

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.
This method atomically increments a counter column in ``row``.
If the counter column does not exist, it is automatically initialized
to ``0`` before being incremented.
:type row: str
:param row: Row key for the row we are incrementing a counter in.
:type column: str
:param column: Column we are incrementing a value in; of the
form ``fam:col``.
:type value: int
:param value: Amount to increment the counter by. (If negative,
this is equivalent to decrement.)
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
temporarily until the method is implemented.
"""
raise NotImplementedError('Temporarily not implemented.')

def counter_dec(self, row, column, value=1):
"""Atomically decrement a counter column.
This method atomically decrements a counter column in ``row``.
If the counter column does not exist, it is automatically initialized
to ``0`` before being decremented.
:type row: str
:param row: Row key for the row we are decrementing a counter in.
:type column: str
:param column: Column we are decrementing a value in; of the
form ``fam:col``.
:type value: int
:param value: Amount to decrement the counter by. (If negative,
this is equivalent to increment.)
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
temporarily until the method is implemented.
"""
raise NotImplementedError('Temporarily not implemented.')
43 changes: 43 additions & 0 deletions gcloud_bigtable/happybase/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,46 @@ def test_batch(self):
with self.assertRaises(NotImplementedError):
table.batch(timestamp=timestamp, batch_size=batch_size,
transaction=transaction)

def test_counter_get(self):
name = 'table-name'
connection = object()
table = self._makeOne(name, connection)

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

def test_counter_set(self):
name = 'table-name'
connection = object()
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):
name = 'table-name'
connection = object()
table = self._makeOne(name, connection)

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

def test_counter_dec(self):
name = 'table-name'
connection = object()
table = self._makeOne(name, connection)

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

0 comments on commit 2e7837c

Please sign in to comment.