def _make_mutations_insert(self, column_family, columns, timestamp, ttl): _pack_name = column_family._pack_name _pack_value = column_family._pack_value _get_type = column_family._get_data_type_for_col if column_family.super: for c, v in columns.iteritems(): cos = ColumnOrSuperColumn() dtype = _get_type(c) if dtype == 'CounterColumnType': subc = [CounterColumn(_pack_name(subname), subvalue) for subname, subvalue in v.iteritems()] cos.counter_super_column = CounterSuperColumn(name=_pack_name(c, True), columns=subc) else: subc = [Column(name=_pack_name(subname), value=_pack_value(subvalue, subname), timestamp=timestamp, ttl=ttl) for subname, subvalue in v.iteritems()] cos.super_column = SuperColumn(name=_pack_name(c, True), columns=subc) yield Mutation(column_or_supercolumn=cos) else: for c, v in columns.iteritems(): cos = ColumnOrSuperColumn() dtype = _get_type(c) if dtype == 'CounterColumnType': cos.counter_column = CounterColumn(_pack_name(c), v) else: cos.column = Column(name=_pack_name(c), value=_pack_value(v, c), timestamp=timestamp, ttl=ttl) yield Mutation(column_or_supercolumn=cos)
def add(self, key, column, value=1, super_column=None, write_consistency_level=None): """ Increment or decrement a counter. `value` should be an integer, either positive or negative, to be added to a counter column. By default, `value` is 1. .. versionadded:: 1.1.0 Available in Cassandra 0.8.0 and later. """ packed_key = self._pack_key(key) cp = self._column_parent(super_column) column = self._pack_name(column) self.pool.execute('add', packed_key, cp, CounterColumn(column, value), write_consistency_level or self.write_consistency_level, allow_retries=self._allow_retries)
def add(self, key, column, value=1, super_column=None, write_consistency_level=None): """ Increment or decrement a counter. `value` should be an integer, either positive or negative, to be added to a counter column. By default, `value` is 1. .. note:: This method is not idempotent. Retrying a failed add may result in a double count. You should consider using a separate ConnectionPool with retries disabled for column families with counters. .. versionadded:: 1.1.0 Available in Cassandra 0.8.0 and later. """ packed_key = self._pack_key(key) cp = self._column_parent(super_column) column = self._pack_name(column) self.pool.execute( 'add', packed_key, cp, CounterColumn(column, value), write_consistency_level or self.write_consistency_level)
def _make_column(name, value, timestamp, ttl): return CounterColumn(name, value)
def _make_counter_cosc(name, value, timestamp, ttl): return ColumnOrSuperColumn(counter_column=CounterColumn(name, value))