hive-to-hbase
在hive中建表 create table if not exists employee ( uid int, uname string, age int, sex string, province string ) stored by 'org.apache.hadoop.hive.hbase.HbaseStorageHandler' with serdeproperties( "hbase.columns.mapping"=":key,base_info:name,base_info:age,base_info:sex,address:provice" ) tblproperties( "hbase.table.name"="mydb:employee" );
导入数据
注意,要使用动态导入数据,不能使用load。 如果想要导入大数据集,可以借助中间表进行动态导入 insert into ..... select ...... from ... 当然:也可以在hbase中直接put数据
hbase-to-hive
drop table mydb2.t1; create external table if not exists mydb2.t1( uid string, uage int, uname string, usex string, province string ) stored by 'org.apache.hadoop.hive.hbase.HbaseStorageHandler' with serdeproperties( "hbase.columns.mapping"=":key,f1:age,f1:name,f1:gender,f2:province" ) tblproperties( "hbase.table.name"="ns1:t1" ); 查询 select * from mydb2.t1;
主要事项
1. 映射hbase的列时,要么就写:key,要么不写,默认使用:key 2. hbase中表存在的时候,在hive中创建表时应该使用external关键字。 3. 如果删除了hbase中对应的表数据,那么hive中就不能查询出来数据。 4. hbase中的列和hive中的列个数和数据类型应该尽量相同,hive表和hbase表的字段不是按照名字匹配,而是按照顺序来匹配的。 5. hive、hbase和mysql等可以使用第三方工具来进行整合。



