@@ -62,6 +62,36 @@ def __init__(self, row_key, table, filter_=None):
62
62
self ._true_pb_mutations = []
63
63
self ._false_pb_mutations = []
64
64
65
+ def _get_mutations (self , state = None ):
66
+ """Gets the list of mutations for a given state.
67
+
68
+ If the state is :data`None` but there is a filter set, then we've
69
+ reached an invalid state. Similarly if no filter is set but the
70
+ state is not :data:`None`.
71
+
72
+ :type state: bool
73
+ :param state: (Optional) The state that the mutation should be
74
+ applied in. Unset if the mutation is not conditional,
75
+ otherwise :data:`True` or :data:`False`.
76
+
77
+ :rtype: list
78
+ :returns: The list to add new mutations to (for the current state).
79
+ :raises: :class:`ValueError <exceptions.ValueError>`
80
+ """
81
+ if state is None :
82
+ if self ._filter is not None :
83
+ raise ValueError ('A filter is set on the current row, but no '
84
+ 'state given for the mutation' )
85
+ return self ._pb_mutations
86
+ else :
87
+ if self ._filter is None :
88
+ raise ValueError ('No filter was set on the current row, but a '
89
+ 'state was given for the mutation' )
90
+ if state :
91
+ return self ._true_pb_mutations
92
+ else :
93
+ return self ._false_pb_mutations
94
+
65
95
def append_cell_value (self , column_family_id , column , value ):
66
96
"""Appends a value to an existing cell.
67
97
@@ -93,35 +123,35 @@ def append_cell_value(self, column_family_id, column, value):
93
123
append_value = value )
94
124
self ._rule_pb_list .append (rule_pb )
95
125
96
- def _get_mutations (self , state = None ):
97
- """Gets the list of mutations for a given state.
98
-
99
- If the state is :data`None` but there is a filter set, then we've
100
- reached an invalid state. Similarly if no filter is set but the
101
- state is not :data:`None`.
102
-
103
- :type state: bool
104
- :param state: (Optional) The state that the mutation should be
105
- applied in. Unset if the mutation is not conditional,
106
- otherwise :data:`True` or :data:`False`.
107
-
108
- :rtype: list
109
- :returns: The list to add new mutations to (for the current state).
110
- :raises: :class:`ValueError <exceptions.ValueError>`
126
+ def increment_cell_value (self , column_family_id , column , int_value ):
127
+ """Increments a value in an existing cell.
128
+ Assumes the value in the cell is stored as a 64 bit integer
129
+ serialized to bytes.
130
+ .. note::
131
+ This method adds a read-modify rule protobuf to the accumulated
132
+ read-modify rules on this :class:`Row`, but does not make an API
133
+ request. To actually send an API request (with the rules) to the
134
+ Google Cloud Bigtable API, call :meth:`commit_modifications`.
135
+ :type column_family_id: str
136
+ :param column_family_id: The column family that contains the column.
137
+ Must be of the form
138
+ ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
139
+ :type column: bytes
140
+ :param column: The column within the column family where the cell
141
+ is located.
142
+ :type int_value: int
143
+ :param int_value: The value to increment the existing value in the cell
144
+ by. If the targeted cell is unset, it will be treated
145
+ as containing a zero. Otherwise, the targeted cell
146
+ must contain an 8-byte value (interpreted as a 64-bit
147
+ big-endian signed integer), or the entire request
148
+ will fail.
111
149
"""
112
- if state is None :
113
- if self ._filter is not None :
114
- raise ValueError ('A filter is set on the current row, but no '
115
- 'state given for the mutation' )
116
- return self ._pb_mutations
117
- else :
118
- if self ._filter is None :
119
- raise ValueError ('No filter was set on the current row, but a '
120
- 'state was given for the mutation' )
121
- if state :
122
- return self ._true_pb_mutations
123
- else :
124
- return self ._false_pb_mutations
150
+ column = _to_bytes (column )
151
+ rule_pb = data_pb2 .ReadModifyWriteRule (family_name = column_family_id ,
152
+ column_qualifier = column ,
153
+ increment_amount = int_value )
154
+ self ._rule_pb_list .append (rule_pb )
125
155
126
156
127
157
class RowFilter (object ):
0 commit comments