掌握使用HBase shell进行表操作

 

(一). 实验环境

(章鱼大数据)HBase

(二). 实验步骤

1.    创建student表,表结构包含info和course列族,显示表结构。

   create 'student','info','course'

 

 

2. 修改表结构,course列族返回最大版本数为3,显示表结构。

alter 'studemt',{'NAME'=>'course','VERSIONS'=>'3'}
desc 'student'

 

 

3. 输入数据,要求至少包括以下列

(具体数据自定,course列族要输入部分小于60分的数据)

info列族:name、age、sex、dept

course列族:english、math、physics

 

put 'student','201601','info:name','liu',4
put 'student','201601','info:age',15
put 'student','201601','info:sex','nv'
put 'student','201601','info:dept','PE'

put 'student','201602','info:name','wang'
put 'student','201602','info:age',16,7
put 'student','201602','info:sex','nan'
put 'student','201602','info:dept','PC'

put 'student','201603','info:name','sun',6
put 'student','201603','info:age',19
put 'student','201603','info:sex','nv'
put 'student','201603','info:dept','JAVA'

put 'student','201601','course:english',72,3
put 'student','201601','course:math',79
put 'student','201601','course:'physics',82

 

put 'student','201602','course:english',62
put 'student','201602','course:math',68,8
put 'student','201602','course:'physics',49


put 'student','201603','course:english',73,8
put 'student','201603','course:math',69
put 'student','201603','course:'physics',48,6

 

 

4. 更新数据,将course列族中小于60的数据更新为60。

 

put 'student','201602','course:physics',60
put 'student','201603','course:physics',60

 

 

5. 使用get进行数据查询。

get 'student','201601',{COLUMN=>'course',TIMERANGE=>3}

get 'student','201603',{COLUMN=>'course',TIMERANGE=>[6,8]}

 

 

6. 使用scan进行查询。

 

scan 'student',{COLUMN => 'info:dept'}


scan 'student',{COLUMN => 'info:name'}

 

7. 使用过滤器进行查询。

scan 'student',{FILTER=>"TimestampFilter(3,8)"}
scan 'student',FILTER=>"RowFilter(=,'substring:2')"

 

 

8. 创建student表的快照stu_snap,显示快照列表。

snapshot 'student','stu_snap'

list_snapshots

 

 

9. 通过快照stu_snap生成新表stu_info,并显示stu_info表结构。

clone_snapshot 'stu_snap','stu_info'

 

 

10. 删除快照stu_snap,删除student表。

delete_snapshot 'stu_snap'

 

 (三)实验总结

   通过这次实验,我学会了Hbase的基本操作,即创建表、对表进行增删改查、利用过滤器查询以及一些快照操作。在创建表时应该注意字母的大小写,Hbase是区分大小写的;在删除表之前,需要先将表禁用,再进行删除;在使用过滤器查询时应注意单词拼写及大小写;snapshot命令可以建立表的快照。