View RSS Feed


Cassandra Delete Operation

Rate this Entry
by , 02-23-2012 at 06:21 PM (1578 Views)
In this section, we will discuss that how we can delete a value from Cassandra database using Java code.
Java Code: This is the code to explain Cassandra Delete Operation
import org.apache.cassandra.thrift.Deletion;
long timestamp =System.currentTimeMillis();
List columns = new ArrayList();
SlicePredicate slicePredicate = new SlicePredicate();
Deletion deletion = new Deletion(timestamp);
Mutation mutation = new Mutation();
List<Mutation> mutations = new ArrayList<Mutation>();
Map<String, List<Mutation>> job = new HashMap<String, List<Mutation>>();
job.put("Authors", mutations);
Map<String, Map<String, List<Mutation>>> batch = 
 new HashMap<String, Map<String, List<Mutation>>>();
batch.put("Ronald Mathies", job);
client.batch_mutate("Blog", batch, ConsistencyLevel.ALL);
It is almost similar to updating data in Cassandra database. Only difference is, we do not create a Columns. We create a Deletion object in this case, which takes a predicate to determine what we are interested to delete. In the above code, SlicePredicate is used to store list of columns which we want to remove from database.

Submit "Cassandra Delete Operation" to Facebook Submit "Cassandra Delete Operation" to Digg Submit "Cassandra Delete Operation" to Submit "Cassandra Delete Operation" to StumbleUpon Submit "Cassandra Delete Operation" to Google