實(shí)驗(yàn):熟悉常用的HBase操作
1實(shí)驗(yàn)?zāi)康?/h3>
- 理解HBase在Hadoop體系結(jié)構(gòu)中的角色;
- 熟練使用HBase操作常用的Shell命令;
2 實(shí)驗(yàn)平臺(tái)
操作系統(tǒng):Linux
Hadoop版本:3.1.3
HBase版本:2.2.2
JDK版本:1.8
3 實(shí)驗(yàn)內(nèi)容和要求
1.用Hadoop提供的HBase Shell命令實(shí)現(xiàn)以下指定功能:
準(zhǔn)備工作:
啟動(dòng)hbash:
./bin/start-hbase.sh
進(jìn)入shell:
hbase shell
(1)列出HBase所有的表的相關(guān)信息,例如表名;
list
(2)在終端打印出指定的表的所有記錄數(shù)據(jù);
scan 'Student'
(3)向已經(jīng)創(chuàng)建好的表添加和刪除指定的列族或列;
在Student表中添加列number
alter 'Student','NAME'=>'number'
在Student表中刪除列number
alter 'Student','NAME'=>'number',METHOD=>'delete'
(4)清空指定的表的所有記錄數(shù)據(jù);
清空custor表的所有記錄數(shù)據(jù)
truncate ‘custor’
(5)統(tǒng)計(jì)表的行數(shù)。
統(tǒng)計(jì)Student表的行數(shù):
count ‘Student’
2.現(xiàn)有以下關(guān)系型數(shù)據(jù)庫(kù)中的表和數(shù)據(jù),要求將其轉(zhuǎn)換為適合于HBase存儲(chǔ)的表并插入數(shù)據(jù):
(1)創(chuàng)建Student表:
create 'Student','S_No','S_Name','S_Sex','S_Age'
添加記錄數(shù)據(jù):
put 'Student','s003','S_No','2015003'
put 'Student','s003','S_Name','Lisi'
put 'Student','s003','S_Sex','male'
put 'Student','s003','S_Age','24'
put 'Course','c001','C_No','123001'
put 'Course','c001','C_Name','Math'
put 'Course','c001','C_Credit','2.0'
put 'Course','c002','C_No','123002'
put 'Course','c002','C_Name','Computer'
put 'Course','c002','C_Credit','5.0'
put 'Course','c003','C_No','123003'
put 'Course','c003','C_Name','English'
put 'Course','c003','C_Credit','3.0'
(2)創(chuàng)建Couse表:
create 'Course','C_No','C_Name','C_Credit'
添加記錄數(shù)據(jù):
put 'Course','c001','C_No','123001'
put 'Course','c001','C_Name','Math'
put 'Course','c001','C_Credit','2.0'
put 'Course','c002','C_No','123002'
put 'Course','c002','C_Name','Computer'
put 'Course','c002','C_Credit','5.0'
put 'Course','c003','C_No','123003'
put 'Course','c003','C_Name','English'
put 'Course','c003','C_Credit','3.0'
(3)創(chuàng)建SC表:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-416227.html
create 'SC','SC_Sno','SC_Cno','SC_Score'
添加記錄數(shù)據(jù):文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-416227.html
put 'SC','sc001','SC_Sno','2015001'
put 'SC','sc001','SC_Cno','123001'
put 'SC','sc001','SC_Score','86'
put 'SC','sc002','SC_Sno','2015001'
put 'SC','sc002','SC_Cno','123003'
put 'SC','sc002','SC_Score','69'
put 'SC','sc003','SC_Sno','2015002'
put 'SC','sc003','SC_Cno','123002'
put 'SC','sc003','SC_Score','77'
put 'SC','sc004','SC_Sno','2015002'
put 'SC','sc004','SC_Cno','123003'
put 'SC','sc004','SC_Score','99'
put 'SC','sc005','SC_Sno','2015003'
put 'SC','sc005','SC_Cno','123001'
put 'SC','sc005','SC_Score','98'
put 'SC','sc006','SC_Sno','2015003'
put 'SC','sc006','SC_Cno','123002'
put 'SC','sc006','SC_Score','95'
感謝支持,若對(duì)您有幫助嗎,一鍵三連!
到了這里,關(guān)于熟悉常用的HBase操作的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!