Skip to content

Commit 1285aa3

Browse files
committed
Adding comments to clarify HappyBase counter_inc().
1 parent 4427dbc commit 1285aa3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gcloud/bigtable/happybase/table.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,25 @@ def counter_inc(self, row, column, value=1):
181181
column = column.decode('utf-8')
182182
column_family_id, column_qualifier = column.split(':')
183183
row.increment_cell_value(column_family_id, column_qualifier, value)
184+
# See row.commit_modifications() will return a dictionary:
185+
# {
186+
# u'col-fam-id': {
187+
# b'col-name1': [
188+
# (b'cell-val', datetime.datetime(...)),
189+
# ...
190+
# ],
191+
# ...
192+
# },
193+
# }
184194
modified_cells = row.commit_modifications()
195+
# Get the cells in the modified column,
185196
column_cells = modified_cells[column_family_id][column_qualifier]
197+
# Make sure there is exactly one cell in the column.
186198
if len(column_cells) != 1:
187199
raise ValueError('Expected server to return one modified cell.')
188-
bytes_value = column_cells[0][0]
200+
column_cell = column_cells[0]
201+
# Get the bytes value from the column and convert it to an integer.
202+
bytes_value = column_cell[0]
189203
int_value, = _UNPACK_I64(bytes_value)
190204
return int_value
191205

0 commit comments

Comments
 (0)