Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convert remove() to batch_mutate(). INCOMPATIBLE CHANGE if using the …

…column keyword argument.
  • Loading branch information...
commit 6186e4946a8018bbaf4960017427dfca4b306ef0 1 parent 3a4dcff
@vomjom vomjom authored
Showing with 29 additions and 18 deletions.
  1. +7 −5 README.mkd
  2. +21 −12 pycassa/columnfamily.py
  3. +1 −1  tests/test_columnfamily.py
View
12 README.mkd
@@ -117,7 +117,7 @@ get_range() returns an iterable. Call it with list() to convert it to a list.
You can remove entire keys or just a certain column.
- >>> cf.remove('bar', column='column1')
+ >>> cf.remove('bar', columns=['column1'])
1261350220106863
>>> cf.get('bar')
{'column2': 'val4'}
@@ -212,7 +212,7 @@ To use SuperColumns, pass super=True to the ColumnFamily constructor.
1261490144457132
>>> cf.get('key1')
{'1': {'sub2': 'val2', 'sub1': 'val1'}, '2': {'sub4': 'val4', 'sub3': 'val3'}}
- >>> cf.remove('key1', '1')
+ >>> cf.remove('key1', super_column='1')
1261490176976864
>>> cf.get('key1')
{'2': {'sub4': 'val4', 'sub3': 'val3'}}
@@ -420,9 +420,11 @@ All the functions have the exact same functionality as their thrift counterparts
Parameters
----------
key : str
- The key to remove. If column is not set, remove all columns
- column : str
- If set, remove only this column or supercolumn
+ The key to remove. If columns is not set, remove all columns
+ columns : list
+ Delete the columns or super_columns in this list
+ super_column : str
+ Delete the columns from this super_column
write_consistency_level : ConsistencyLevel
Affects the guaranteed replication factor before returning from
any write operation
View
33 pycassa/columnfamily.py
@@ -5,7 +5,7 @@
pass
from cassandra.ttypes import Column, ColumnOrSuperColumn, ColumnParent, \
ColumnPath, ConsistencyLevel, NotFoundException, SlicePredicate, \
- SliceRange, SuperColumn, Mutation
+ SliceRange, SuperColumn, Mutation, Deletion
import time
@@ -338,16 +338,18 @@ def insert(self, key, columns, write_consistency_level = None):
self._wcl(write_consistency_level))
return timestamp
- def remove(self, key, column=None, write_consistency_level = None):
+ def remove(self, key, columns=None, super_column=None, write_consistency_level = None):
"""
- Remove a specified key or column
+ Remove a specified key or columns
Parameters
----------
key : str
- The key to remove. If column is not set, remove all columns
- column : str
- If set, remove only this column or supercolumn
+ The key to remove. If columns is not set, remove all columns
+ columns : list
+ Delete the columns or super_columns in this list
+ super_column : str
+ Delete the columns from this super_column
write_consistency_level : ConsistencyLevel
Affects the guaranteed replication factor before returning from
any write operation
@@ -356,11 +358,18 @@ def remove(self, key, column=None, write_consistency_level = None):
-------
int timestamp
"""
- if self.super:
- cp = ColumnPath(column_family=self.column_family, super_column=column)
- else:
- cp = ColumnPath(column_family=self.column_family, column=column)
timestamp = self.timestamp()
- self.client.remove(self.keyspace, key, cp, timestamp,
- self._wcl(write_consistency_level))
+ if columns is not None:
+ # Deletion doesn't support SliceRange predicates as of Cassandra 0.6.0,
+ # so we can't add column_start, column_finish, etc... yet
+ sp = SlicePredicate(column_names=columns)
+ deletion = Deletion(timestamp=timestamp, super_column=super_column, predicate=sp)
+ mutation = Mutation(deletion=deletion)
+ self.client.batch_mutate(self.keyspace,
+ {key: {self.column_family: [mutation]}},
+ self._wcl(write_consistency_level))
+ else:
+ cp = ColumnPath(column_family=self.column_family, super_column=super_column)
+ self.client.remove(self.keyspace, key, cp, timestamp,
+ self._wcl(write_consistency_level))
return timestamp
View
2  tests/test_columnfamily.py
@@ -87,7 +87,7 @@ def test_remove(self):
columns = {'1': 'val1', '2': 'val2'}
self.cf.insert(key, columns)
- self.cf.remove(key, '2')
+ self.cf.remove(key, columns=['2'])
del columns['2']
assert self.cf.get(key) == {'1': 'val1'}
Please sign in to comment.
Something went wrong with that request. Please try again.