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 cfc20f2

Browse filesBrowse files
committed
Merge pull request #1388 from dhermes/bigtable-append-cell-value
Adding Bigtable Row.append_cell_value.
2 parents 0b602ea + d8d1ed8 commit cfc20f2
Copy full SHA for cfc20f2

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+49
-0
lines changed

‎gcloud/bigtable/row.py

Copy file name to clipboardExpand all lines: gcloud/bigtable/row.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,38 @@ def __init__(self, row_key, table, filter_=None):
4242
self._row_key = _to_bytes(row_key)
4343
self._table = table
4444
self._filter = filter_
45+
self._rule_pb_list = []
46+
47+
def append_cell_value(self, column_family_id, column, value):
48+
"""Appends a value to an existing cell.
49+
50+
.. note::
51+
52+
This method adds a read-modify rule protobuf to the accumulated
53+
read-modify rules on this :class:`Row`, but does not make an API
54+
request. To actually send an API request (with the rules) to the
55+
Google Cloud Bigtable API, call :meth:`commit_modifications`.
56+
57+
:type column_family_id: str
58+
:param column_family_id: The column family that contains the column.
59+
Must be of the form
60+
``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
61+
62+
:type column: bytes
63+
:param column: The column within the column family where the cell
64+
is located.
65+
66+
:type value: bytes
67+
:param value: The value to append to the existing value in the cell. If
68+
the targeted cell is unset, it will be treated as
69+
containing the empty string.
70+
"""
71+
column = _to_bytes(column)
72+
value = _to_bytes(value)
73+
rule_pb = data_pb2.ReadModifyWriteRule(family_name=column_family_id,
74+
column_qualifier=column,
75+
append_value=value)
76+
self._rule_pb_list.append(rule_pb)
4577

4678

4779
class RowFilter(object):

‎gcloud/bigtable/test_row.py

Copy file name to clipboardExpand all lines: gcloud/bigtable/test_row.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ def test_constructor_with_non_bytes(self):
4949
with self.assertRaises(TypeError):
5050
self._makeOne(row_key, None)
5151

52+
def test_append_cell_value(self):
53+
from gcloud.bigtable._generated import bigtable_data_pb2 as data_pb2
54+
55+
table = object()
56+
row_key = b'row_key'
57+
row = self._makeOne(row_key, table)
58+
self.assertEqual(row._rule_pb_list, [])
59+
60+
column = b'column'
61+
column_family_id = u'column_family_id'
62+
value = b'bytes-val'
63+
row.append_cell_value(column_family_id, column, value)
64+
expected_pb = data_pb2.ReadModifyWriteRule(
65+
family_name=column_family_id, column_qualifier=column,
66+
append_value=value)
67+
self.assertEqual(row._rule_pb_list, [expected_pb])
68+
5269

5370
class Test_BoolFilter(unittest2.TestCase):
5471

0 commit comments

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