Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ab8edc

Browse filesBrowse files
committed
Merge pull request #1541 from dhermes/happybase-counter-set
Adding HappyBase Table.counter_set().
2 parents 43674b9 + cdcc1a8 commit 2ab8edc
Copy full SHA for 2ab8edc

File tree

Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed

‎gcloud/bigtable/happybase/table.py

Copy file name to clipboardExpand all lines: gcloud/bigtable/happybase/table.py
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,30 @@ def counter_get(self, row, column):
554554
# is correctly initialized if didn't exist yet.
555555
return self.counter_inc(row, column, value=0)
556556

557+
def counter_set(self, row, column, value=0):
558+
"""Set a counter column to a specific value.
559+
560+
This method is provided in HappyBase, but we do not provide it here
561+
because it defeats the purpose of using atomic increment and decrement
562+
of a counter.
563+
564+
:type row: str
565+
:param row: Row key for the row we are setting a counter in.
566+
567+
:type column: str
568+
:param column: Column we are setting a value in; of
569+
the form ``fam:col``.
570+
571+
:type value: int
572+
:param value: Value to set the counter to.
573+
574+
:raises: :class:`NotImplementedError <exceptions.NotImplementedError>`
575+
always
576+
"""
577+
raise NotImplementedError('Table.counter_set will not be implemented. '
578+
'Instead use the increment/decrement '
579+
'methods along with counter_get.')
580+
557581
def counter_inc(self, row, column, value=1):
558582
"""Atomically increment a counter column.
559583

‎gcloud/bigtable/happybase/test_table.py

Copy file name to clipboardExpand all lines: gcloud/bigtable/happybase/test_table.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,17 @@ def _counter_inc_helper(self, row, column, value, commit_result):
886886
self.assertEqual(row_obj.counts,
887887
{tuple(column.split(':')): incremented_value})
888888

889+
def test_counter_set(self):
890+
name = 'table-name'
891+
connection = None
892+
table = self._makeOne(name, connection)
893+
894+
row = 'row-key'
895+
column = 'fam:col1'
896+
value = 42
897+
with self.assertRaises(NotImplementedError):
898+
table.counter_set(row, column, value=value)
899+
889900
def test_counter_inc(self):
890901
import struct
891902

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.