Skip to content

Instantly share code, notes, and snippets.

@jnatkins
Created March 7, 2013 20:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jnatkins/5111513 to your computer and use it in GitHub Desktop.
Test deleting a single HBase cell, while avoiding masking of earlier versions.
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));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment