package api;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
public class PutExample {
public static void main(String[] args) throws IOException {
Configuration cfg = HBaseConfiguration.create();
HTable hTable = new HTable(cfg,"xyj");
Put put =new Put(Bytes.toBytes("r3"));
//fam qulifier value
put.add(Bytes.toBytes("cf1"),Bytes.toBytes("qual1"),Bytes.toBytes("val1"));
put.add(Bytes.toBytes("cf1"),Bytes.toBytes("qual2"),Bytes.toBytes("val2"));
put.add(Bytes.toBytes("cf1"),Bytes.toBytes("qual3"),Bytes.toBytes("val3"));
hTable.put(put);
}
}
//hbase(main):001:0> create 'xyj','cf1'
//hbase(main):004:0> put 'xyj' ,'r1','cf1:q1','v1'
//0 row(s) in 0.0160 seconds
//
//hbase(main):005:0> put 'xyj' ,'r2','cf1:q2','v2'
//0 row(s) in 0.0100 seconds
//
//hbase(main):006:0> put 'xyj' ,'r2','cf1:q3','v3'
//0 row(s) in 0.0160 seconds
//
//hbase(main):007:0> list 'xyj'
//TABLE
//xyj
//1 row(s) in 0.1330 seconds
//hbase(main):009:0> scan 'xyj'
//ROW COLUMN+CELL
// r1 column=cf1:q1, timestamp=1511597241994, value=v1
// r2 column=cf1:q2, timestamp=1511597275233, value=v2
// r2 column=cf1:q3, timestamp=1511597290730, value=v3
// r3 column=cf1:qual1, timestamp=1511597438929, value=val1
// r3 column=cf1:qual2, timestamp=1511597438929, value=val2
// r3 column=cf1:qual3, timestamp=1511597438929, value=val3
//3 row(s) in 0.0510 seconds