HBase基本操作

先创建表和列族然后才能添加数据

hbase(main):014:0> create 'nvshen','baseinfo','extrainfo'
0 row(s) in 4.3740 seconds
hbase(main):016:0> describe 'nvshen'
DESCRIPTION                                                                     ENABLED                                    
 'nvshen', {NAME => 'baseinfo', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => ' true                                       
 ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VE                                            
 RSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE =                                            
 > '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, 
 {NAME => 'extrainfo',  DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',                                            
  VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '21474836                                            
 47', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false'                                            
 , BLOCKCACHE => 'true'}                                                                                                   
1 row(s) in 0.0690 seconds
然后再进行api相关操作

	@Test
	public void TestInsert() throws Exception{
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", "集群的主机名和zk的端口号");
		
		HTable nvshen = new HTable(conf,"nvshen");
		
		//用来对单个行执行添加操作
		Put name = new Put(Bytes.toBytes("rk001"));
		name.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("name"), Bytes.toBytes("zheng"));
		
		Put age = new Put(Bytes.toBytes("rk001"));
		age.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("age"), Bytes.toBytes(20));
		age.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("age"), Bytes.toBytes(19));
		
		ArrayList<Put> puts = new ArrayList<>();
		puts.add(age);
		puts.add(name);
		nvshen.put(puts);
	}
查看hbase表

hbase(main):017:0> scan 'nvshen'
ROW                             COLUMN+CELL                                                                                
 rk001                          column=baseinfo:age, timestamp=1493194117575, value=\x00\x00\x00\x13                       
 rk001                          column=baseinfo:name, timestamp=1493194117575, value=zheng                                 
1 row(s) in 0.0180 seconds





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值