public
Created

Test deleting a single HBase cell, while avoiding masking of earlier versions.

  • Download Gist
DeleteTest.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
package org.kiji.examples.importers;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
 
public class DeleteTest extends Configured implements Tool {
 
@Override
public int run(String[] args) throws Exception {
setConf(HBaseConfiguration.addHbaseResources(getConf()));
 
/* Open the HBase table */
HTable htable = new HTable(getConf(), "del_test");
 
List<Put> puts = new ArrayList<Put>();
for (int i = 1; i <= 5; i++) {
Put put = new Put(Bytes.toBytes("key"));
put.add(Bytes.toBytes("f1"), Bytes.toBytes("c1"), i, Bytes.toBytes("value" + i));
puts.add(put);
}
htable.put(puts);
 
Delete del = new Delete(Bytes.toBytes("key"));
del.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("c1"), 3);
htable.delete(del);
 
return 0;
}
 
public static void main(String args[]) throws Exception {
System.exit(ToolRunner.run(new DeleteTest(), args));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.