#创建表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作为行键,这样能保证新写入的数据在读取时可以被快速命中。