HBase练习

#创建表t1,列族为f1
hbase(main):067:0> create 't1','f1'

#查看命名空间default中的表
hbase(main):070:0> list_namespace_tables 'default'
TABLE                                                                                
t1

#查看表t1的描述
hbase(main):073:0> describe 't1'
Table t1 is ENABLED                                                             
t1                                                                              
COLUMN FAMILIES DESCRIPTION                                                     
{NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_
SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL =
> 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => '
false', BLOCKCACHE => 'true'}   

#添加列族f2
hbase(main):074:0> alter 't1',NAME=>'f2'
Updating all regions with the new schema...
1/1 regions updated.
Done.

#再次查看表t1的描述
hbase(main):075:0> describe 't1'
Table t1 is ENABLED                                                             
t1                                                                              
COLUMN FAMILIES DESCRIPTION                                                     
{NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_
SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL =
> 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => '
false', BLOCKCACHE => 'true'}                                                   
{NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_
SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => 'FOREVER', MIN_VERS
IONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => '
false', BLOCKCACHE => 'true'}

#插入一条数据,行row1
hbase(main):076:0> put 't1','row1','f1:c1','value1',1423454345987

#查看新插入的数据
hbase(main):080:0> get 't1','row1','f1:c1'
COLUMN                CELL                                                      
 f1:c1                timestamp=1423454345987, value=value1

#插入多条数据
hbase(main):086:0> put 't1','r2','f1:c1','value2',1423454345922
hbase(main):090:0> put 't1','xx','f1:c1','value4',1423454345944
hbase(main):092:0> put 't1','aa','f1:c1','value5',1423454345955

#查看t1中插入的数据
hbase(main):093:0> scan 't1'
ROW                     COLUMN+CELL                                                     
 aa                     column=f1:c1, timestamp=1423454345955, value=value5             
 r2                     column=f1:c1, timestamp=1423454345922, value=value2             
 row1                   column=f1:c1, timestamp=1423454345987, value=value1                          
 xx                     column=f1:c1, timestamp=1423454345944, value=value4   

可以发现HBase不是以时间来排序的,是以row的字典序排序,row可以自定义。
可以使用Long.MAX_VALUE - timestamp作为行键,这样能保证新写入的数据在读取时可以被快速命中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值