Cassandra Delete Operation
by, 02-23-2012 at 06:21 PM (1480 Views)
In this section, we will discuss that how we can delete a value from Cassandra database using Java code.
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.Java Code: This is the code to explain Cassandra Delete Operationimport org.apache.cassandra.thrift.Deletion; ... long timestamp =System.currentTimeMillis(); List columns = new ArrayList(); columns.add("email".getBytes()); SlicePredicate slicePredicate = new SlicePredicate(); slicePredicate.setColumn_names(columns); Deletion deletion = new Deletion(timestamp); deletion.setPredicate(slicePredicate); Mutation mutation = new Mutation(); mutation.setDeletion(deletion); List<Mutation> mutations = new ArrayList<Mutation>(); mutations.add(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);