這篇文章將為大家詳細講解有關如何使用Hive外部表導入HBase,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
達日ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
創(chuàng)建hbase表
(1) 建立一個表格classes具有1個列族user
create 'classes','user'
(2) 查看表的構造
hbase(main):005:0> describe 'classes' DESCRIPTION ENABLED 'classes', {NAME => 'user', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', true VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => ' false', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
(3) 加入2行數(shù)據(jù)
put 'classes','001','user:name','jack' put 'classes','001','user:age','20' put 'classes','002','user:name','liza' put 'classes','002','user:age','18'
(4) 查看classes中的數(shù)據(jù)
hbase(main):016:0> scan 'classes' ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza
(5) 創(chuàng)建外部hive表,查詢驗證
create external table classes(id int, name string, age int) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,user:name,user:age") TBLPROPERTIES("hbase.table.name" = "classes"); select * from classes; OK 1 jack 20 2 liza 18
(6)再添加數(shù)據(jù)到HBase
put 'classes','003','user:age','1820183291839132' hbase(main):025:0> scan 'classes' ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza 003 column=user:age, timestamp=1404981476497, value=1820183291839132
(7)Hive查詢,看看新數(shù)據(jù)
select * from classes; OK 1 jack 20 2 liza 18 3 NULL NULL --這里是null了,因為003沒有name,所以補位Null,而age為Null是因為超過最大值
(8)如下作為驗證
put 'classes','004','user:name','test' put 'classes','004','user:age','1820183291839112312' -- 已經(jīng)超int了 hbase(main):030:0> scan 'classes' ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza 003 column=user:age, timestamp=1404981476497, value=1820183291839132 004 column=user:age, timestamp=1404981558125, value=1820183291839112312 004 column=user:name, timestamp=1404981551508, value=test select * from classes; 1 jack 20 2 liza 18 3 NULL NULL 4 test NULL -- 超int后也認為是null put 'classes','005','user:age','1231342' hbase(main):034:0* scan 'classes' ROW COLUMN+CELL 001 column=user:age, timestamp=1404980824151, value=20 001 column=user:name, timestamp=1404980772073, value=jack 002 column=user:age, timestamp=1404980963764, value=18 002 column=user:name, timestamp=1404980953897, value=liza 003 column=user:age, timestamp=1404981476497, value=1820183291839132 004 column=user:age, timestamp=1404981558125, value=1820183291839112312 004 column=user:name, timestamp=1404981551508, value=test 005 column=user:age, timestamp=1404981720600, value=1231342 select * from classes; 1 jack 20 2 liza 18 3 NULL NULL 4 test NULL 5 NULL 1231342
關于“如何使用Hive外部表導入HBase”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。