这篇文章将为大家详细讲解有关如何使用Hive外部表导入HBase,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
达日ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
创建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行数据
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中的数据
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) 创建外部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)再添加数据到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查询,看看新数据
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' -- 已经超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”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。