HBase Get example
Source Code
package org.hadoop.dna.analyzer;
import java.io.IOException;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class TrafficGet {
/**
* hbase table write example
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
Configuration config = HBaseConfiguration.create();
config.addResource(new Path("/usr/local/hbase/conf/hbase-default.xml"));
config.addResource(new Path("/usr/local/hbase/conf/hbase-site.xml"));
// Load Hbase table
HTable htable = new HTable(config, "Traffic");
// Get
// rowkey1 : B:<Dst IP> -> xx:xx bytes
Get get = new Get(Bytes.toBytes("2012-05-09-09-35-192.168.210.20"));
get.addColumn(Bytes.toBytes("B"), Bytes.toBytes("108.61.73.243"));
Result result = htable.get(get);
byte[] val = result.getValue(Bytes.toBytes("B"), Bytes.toBytes("108.61.73.243"));
System.out.println("Value:" + Bytes.toString(val));
} catch (IOException e) {
System.out.println("IOExeption: cannot insert table");
e.printStackTrace();
}
}
}