2 row(s) in seconds 4) drop一个表
hbase(main):029:0>disable 'temp_table' 0 row(s) in
hbase(main):030:0>drop 'temp_table' 0 row(s) in
5) 判断表是否enable
hbase(main):016:0> is_enabled 'member'
true 0 row(s) in seconds 6) 判断表是否disable
hbase(main):032:0>is_disabled 'member'
false 0 row(s) in 3. DML操作 1) 插入几条记录
put'member','scutshuxue','info:age','24'
put'member','scutshuxue','info:birthday','1987-06-17' put'member','scutshuxue','info:company','alibaba' put'member','scutshuxue','address:contry','china' put'member','scutshuxue','address:province','zhejiang' put'member','scutshuxue','address:city','hangzhou' put'member','xiaofeng','info:birthday','1987-4-17' put'member','xiaofeng','info:favorite','movie' put'member','xiaofeng','info:company','alibaba' put'member','xiaofeng','address:contry','china'
put'member','xiaofeng','address:province','guangdong' put'member','xiaofeng','address:city','jieyang' put'member','xiaofeng','address:town','xianqiao' 2) 获取一条数据 获取一个id的所有数据
hbase(main):003:0> get 'member','scutshuxue'
COLUMN CELL
address:city timestamp=, value=hangzhou
address:contry timestamp=, value=china
address:province timestamp=, value=zhejiang
info:age timestamp=, value=24
info:birthday timestamp=, value=1987-06-17
info:company timestamp=, value=alibaba 6 row(s) in seconds
获取一个id的所有数据获取一个id,一个列族中一个列的所有数据 hbase(main):026:0> get 'member','scutshuxue','info'
COLUMN CELL
info:age timestamp=, value=24
info:birthday timestamp=, value=1987-06-17
info:company timestamp=, value=alibaba 3 row(s) in seconds 3) .更新一条记录
hbase(main):027:0> put 'member','scutshuxue','info:age' ,'99' 0 row(s) in seconds
4) 通过timestamp来获取两个版本的数据
hbase(main):028:0> get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>}
COLUMN CELL
0 row(s) in seconds 5) 全表扫描
hbase(main):029:0> scan 'member'
ROW COLUMN+CELL scutshuxue column=address:city, timestamp=, value=hangzhou scutshuxue column=address:contry, timestamp=, value=china scutshuxue column=address:province, timestamp=, value=zhejiang scutshuxue column=info:age, timestamp=, value=99 scutshuxue column=info:birthday, timestamp=, value=1987-06-17 scutshuxue column=info:company, timestamp=, value=alibaba xiaofeng column=address:city, timestamp=, value=jieyang xiaofeng column=address:contry, timestamp=, value=china xiaofeng column=address:province, timestamp=, value=guangdong xiaofeng column=address:town, timestamp=, value=xianqiao xiaofeng column=info:birthday, timestamp=, value=1987-4-17 xiaofeng column=info:company, timestamp=,
value=alibaba xiaofeng column=info:favorite, timestamp=, value=movie 2 row(s) in seconds
6) 删除id为temp的值的‘info:age’字段
hbase(main):030:0> delete 'member','temp','info:age' 0 row(s) in seconds 7) 删除整行
hbase(main):031:0> deleteall 'member','xiaofeng' 0 row(s) in seconds 8) 查询表中有多少行
hbase(main):032:0> count 'member' 1 row(s) in seconds => 1
9) 给‘xiaofeng’这个id增加'info:age'字段,并使用counter实现递增获 hbase(main):033:0> incr 'member','xiaofeng','info:age' COUNTER VALUE = 1 0 row(s) in seconds
取当前count的值hbase(main):034:0> get_counter 'member','xiaofeng','info:age' COUNTER VALUE = 1 10) 将整张表清空
hbase(main):035:0> truncate 'member'
Truncating 'member' table (it may take a while): - Disabling table... - Truncating table... 0 row(s) in seconds
7.2.3 运行案例
1. 导入用户数据表
将文件上传到HDFS文件系统中: # hadoop fs -put /data/hbase/ # hadoop fs -ls /data/hbase/ 在HBase中创建user表:
hbase(main):003:0> create 'user','info' 0 row(s) in seconds => Hbase::Table – user
运行MapReduce任务,导入数据,首先生成Hfile文件: #
hbase
=\
=HBASE_ROW_KEY,info:name,info:age
user
,可以看到生成的HFile文件
将HFile数据导入user表中: # hbase user