@@ -287,50 +287,56 @@ def _to_dict(self) -> dict[str, Any]:
287287@dataclass
288288class AddToCell (Mutation ):
289289 """
290- Mutation to add a value to an aggregate cell.
290+ Adds an int64 value to an aggregate cell. The column family must be an
291+ aggregate family and have an "int64" input type or this mutation will be
292+ rejected.
291293
294+ Note: The timestamp values are in microseconds but must match the
295+ granularity of the table (defaults to `MILLIS`). Therefore, the given value
296+ must be a multiple of 1000 (millisecond granularity). For example:
297+ `1571902339435000`.
292298
293299 Args:
294300 family: The name of the column family to which the cell belongs.
295301 qualifier: The column qualifier of the cell.
296302 value: The value to be accumulated into the cell.
297- timestamp_micros: The timestamp of the cell.
303+ timestamp_micros: The timestamp of the cell. Must be provided for
304+ cell aggregation to work correctly.
305+
298306
299307 Raises:
300308 TypeError: If `qualifier` is not `bytes` or `str`.
301309 TypeError: If `value` is not `int`.
302- ValueError: If `timestamp_micros` is less than `_SERVER_SIDE_TIMESTAMP`.
310+ TypeError: If `timestamp_micros` is not `int`.
311+ ValueError: If `timestamp_micros` is less than 0.
303312 """
304313
305314 def __init__ (
306315 self ,
307316 family : str ,
308317 qualifier : bytes | str ,
309318 value : int ,
310- timestamp : int | None = None ,
319+ timestamp_micros : int ,
311320 ):
312321 qualifier = qualifier .encode () if isinstance (qualifier , str ) else qualifier
313322 if not isinstance (qualifier , bytes ):
314323 raise TypeError ("qualifier must be bytes or str" )
315324 if not isinstance (value , int ):
316325 raise TypeError ("value must be int" )
326+ if not isinstance (timestamp_micros , int ):
327+ raise TypeError ("value must be int" )
317328 if abs (value ) > _MAX_INCREMENT_VALUE :
318329 raise ValueError (
319330 "int values must be between -2**63 and 2**63 (64-bit signed int)"
320331 )
321332
322- if timestamp is None :
323- # use current timestamp, with milisecond precision
324- timestamp = time .time_ns () // 1000
325- timestamp = timestamp - (timestamp % 1000 )
326-
327- if timestamp < 0 :
328- raise ValueError ("timestamp must be positive" )
333+ if timestamp_micros < 0 :
334+ raise ValueError ("timestamp must be non-negative" )
329335
330336 self .family = family
331337 self .qualifier = qualifier
332338 self .value = value
333- self .timestamp = timestamp
339+ self .timestamp = timestamp_micros
334340
335341 def _to_dict (self ) -> dict [str , Any ]:
336342 return {
0 commit comments