Database Reference
In-Depth Information
The following code snippet shows how to do this. First, you create a SlicePredicate object to
hold the names of the columns you want to delete. Here we just want to delete the “b” column.
Then, you create a Deletion object that sets this predicate, and create a Mutation that sets this
Deletion .
Once you have the Deletion object set up, you can create your mutation map. This map uses a
byte array key to point to the deletions you want to make, so you can use different keys with the
same or different mutation objects to perform the batch delete. These keys point to another map,
which itself uses a string as the key to name the column family to modify. That map key points
to a list of mutations that should be performed.
String columnFamily = "Standard1";
byte[] key = "k2".getBytes(); //this is the row key
Clock clock = new Clock(System.currentTimeMillis());
SlicePredicate delPred = new SlicePredicate();
List<byte[]> delCols = new ArrayList<byte[]>();
//let's delete the column named 'b', though we could add more
delCols.add("b".getBytes());
delPred.column_names = delCols;
Deletion deletion = new Deletion();
deletion.predicate = delPred;
deletion.clock = clock;
Mutation mutation = new Mutation();
mutation.deletion = deletion;
Map<byte[], Map<String, List<Mutation>>> mutationMap =
new HashMap<byte[], Map<String, List<Mutation>>>();
List<Mutation> mutationList = new ArrayList<Mutation>();
mutationList.add(mutation);
Map<String, List<Mutation>> m = new HashMap<String, List<Mutation>>();
m.put(columnFamily, mutationList);
//just for this row key, though we could add more
mutationMap.put(key, m);
client.batch_mutate(mutationMap, ConsistencyLevel.ALL);
There is a second way to specify items to delete using the Deletion structure: you can use a
SliceRange instead of a List of columns, so you can delete by range instead of explicitly listing
column names.
Search WWH ::




Custom Search