今天继续学习 HBase 命令行操作,详细操作如下
四、DML 操作语言
DML 是数据操作语言,用户可以通过这些语言实现对数据的基本操作,包括数据的增删改查
HBase DML 命令有 append、 count、 delete、 deleteall、 get、 get_counter、 get_splits、 incr、 put、 scan、 truncate、 truncate_preserve 等
1、HBase 表中添加数据
put 语法如下:
hbase> put 'ns1:t1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value', ts1
hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{
'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{
'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
实例:
hbase(main):020:0> describe 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.0260 seconds
# 向表 test 中放入两条数据
hbase(main):017:0* put 'test','001','info','luo'
put 'test','002','info','luo_ff'
0 row(s) in 0.0640 seconds
hbase(main):022:0> put 'test','002','info','luo_ff'
0 row(s) in 0.0090 seconds
2、统计表中数据条数
hbase(main):023:0> count 'test'
2 row(s) in 0.0040 seconds
=> 2
3、查看表中数据
HBase 中数据的浏览有两种方式,一种是全表扫描,一种是指定获取到一条数据,全表扫描 用 scan 命令,指定获取某条数据 用 get 命令,具体使用如下:
3.1 scan 全表扫描
命令语法如下:
Some examples:
hbase> scan 'hbase:meta'
hbase> scan 'hbase:meta', {
COLUMNS => 'info:regioninfo'}
hbase> scan 'ns1:t1', {
COLUMNS =>