Reputation: 11
I'm trying to delete an Accumulo row on a table. The table looks like this:
Key: id0001 hero:alias [secretId] 1525804166026 false Value: Batman
Key: id0001 hero:name [secretId] 1525804166026 false Value: Bruce Wayne
Key: id0001 hero:wearsCape? [secretId] 1525804166026 false Value: true
Key: id0002 hero:alias [] 1525804166026 false Value: Robin
Key: id0002 hero:name [secretId] 1525804166026 false Value: Dick Grayson
Key: id0002 hero:wearsCape? [secretId] 1525804166026 false Value: true
Key: id0003 hero:alias [] 1525804166026 false Value: Joker
Key: id0003 hero:name [] 1525804166026 false Value: Unknown
Key: id0003 hero:wearsCape? [] 1525804166026 false Value: false
I'm trying to delete row with ID "id0001", ColFam "hero", ColQual "name". My code is like this:
Mutation mut = new Mutation("id0001");
mut.putDelete(new Text("hero"), new Text("name"));
try (Scanner scanner1 = commishConn.createScanner("GothamPD", new Authorizations("secretId"))) {
//scanner1.setRange(Range.exact("id0001"));
for (Entry<Key,Value> entry : scanner1) {
mut.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
}
}
BatchWriter batchwriter = conn.createBatchWriter("GothamPD",1000000, 60000, 2);
batchwriter.addMutation(mut);
batchwriter.flush();
It's not deleting even though, I have specified the authorization.
Upvotes: 1
Views: 230
Reputation: 2512
The ColumnVisibility
is part of the column. You need to include it if you are going to delete an entry with a non-empty visibility.
The Mutation.putDelete
method has a variation which accepts a third parameter for the ColumnVisibility
.
For example, replace:
for (Entry<Key,Value> entry : scanner1) {
mut.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier());
}
with the following:
for (Entry<Key,Value> entry : scanner1) {
Key k = entry.getKey();
mut.putDelete(k.getColumnFamily(), k.getColumnQualifier(), k.getColumnVisibilityParsed());
}
WARNING: Be careful with this; this scan-and-delete loop will delete all data found by the scanner.
Note: the putDelete
before your scanner loop is redundant; it would already be deleted, if it exists, in the loop.
Upvotes: 0