从关系库导入数据到hive-hbase表中
2015-08-24 13:57
435 查看
[Author]: kwu
从关系库导入数据到hive-hbase表中,关系库到hbase中,可以直接由sqoop来导入,但是我们要对rowkey做特殊处理并加入更新时间,则操作步骤如下:
1、创建hive与hbase的表
1)创建hbase表
命令行输入 hbase shell 进入hbase的终端:
查询hbase创建的表
如需删除表
2)创建hive的外表
2、自动化的shell脚本
3、说明
1) stage.location_tmp为临时中转表,本次ETL完后即删除。
2)--where "1=1" 可设置关系库的查询语句
3)reverse(ID) 对hbase的rowkey自动逆序处理
4)insert into 到hbase中自动根据rowkey来去重
5)udf_getbfhourstime(0) 自定义函数,取的是当前时间
从关系库导入数据到hive-hbase表中,关系库到hbase中,可以直接由sqoop来导入,但是我们要对rowkey做特殊处理并加入更新时间,则操作步骤如下:
1、创建hive与hbase的表
1)创建hbase表
命令行输入 hbase shell 进入hbase的终端:
create 'location','cf1'
查询hbase创建的表
list
如需删除表
disable 'location' drop 'location'
2)创建hive的外表
hive -e" drop TABLE ods.hbase_location; CREATE EXTERNAL TABLE ods.hbase_location(key string , ID int comment '唯一ID', location1 string comment '国家代号' , location2 string comment '省份代号' , location3 string comment '城市代号', country string comment '国家(中文)', cn string comment '省份(中文)', cn_city string comment '城市(中文)', cn_district string comment '城市所属地区(中文)', py string comment '省份缩略(拼音)', en_city string comment '城市(英文)', en_district string comment '城市所属地区(英文)', en string comment '省份(英文)', geoid INT comment '行政区划代码', updatetime string comment '更新时间' ) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES (\"hbase.columns.mapping\" = \":key, cf1:ID, cf1:location1, cf1:location2, cf1:location3, cf1:country, cf1:cn, cf1:cn_city, cf1:cn_district, cf1:py, cf1:en_city, cf1:en_district, cf1:en, cf1:geoid, cf1:updatetime\") TBLPROPERTIES(\"hbase.table.name\" = \"location\"); "
2、自动化的shell脚本
#!/bin/sh # upload logs to hdfs today=`date --date='0 days ago' +%Y-%m-%d` hive -e" drop table stage.location_tmp; CREATE TABLE stage.location_tmp ( ID INT comment '唯一ID', location1 string comment '国家代号' , location2 string comment '省份代号' , location3 string comment '城市代号', country string comment '国家(中文)', cn string comment '省份(中文)', cn_city string comment '城市(中文)', cn_district string comment '城市所属地区(中文)', py string comment '省份缩略(拼音)', en_city string comment '城市(英文)', en_district string comment '城市所属地区(英文)', en string comment '省份(英文)', geoid INT comment '行政区划代码' ) ROW FORMAT DELIMITED fields terminated by '\001' STORED AS TEXTFILE; " sqoop import --connect jdbc:mysql://10.130.2.6:3306/bdc_test --username lvwenjuan --password Abcd1234 --table location --where "1=1" --columns "ID ,location1 ,location2 ,location3 ,country ,cn ,cn_city , cn_district ,py , en_city , en_district ,en , geoid " --fields-terminated-by '\001' --hive-import --hive-drop-import-delims --hive-table stage.location_tmp -m 1 hive -e" insert into table ods.hbase_location select reverse(ID) , ID , location1 , location2 , location3 , country, cn, cn_city, cn_district, py, en_city, en_district, en string, geoid , udf_getbfhourstime(0) from stage.location_tmp;" hive -e "drop TABLE stage.location_tmp;"
3、说明
1) stage.location_tmp为临时中转表,本次ETL完后即删除。
2)--where "1=1" 可设置关系库的查询语句
3)reverse(ID) 对hbase的rowkey自动逆序处理
4)insert into 到hbase中自动根据rowkey来去重
5)udf_getbfhourstime(0) 自定义函数,取的是当前时间
相关文章推荐
- [LeedCode OJ]#120 Triangle
- 中间件简单
- 【敏捷】扑克牌估算
- 做得到么
- jquery 元素选择器集合
- Spring MVC 原理详解
- 【NOIP2003TG/codevs1085】 数字游戏 解题报告
- Shell脚本查看linux系统性能瓶颈
- KMP算法
- C++ 入门教程(二) 第一个C++程序:Hello World
- Android SDK 在线更新镜像服务器资源
- 图像处理职位面试题(图像处理+c++)
- 黑马程序员-------Java笔记-------IO题(常见的2种题型)
- Android SurfaceView实战 打造抽奖转盘
- 【Apple文档阅读笔记】View编程指南---View
- C# 中的委托和事件【转载】
- Examining Open vSwitch Traffic Patterns
- Sqlite学习笔记(三)&&WAL性能测试
- jQuery 表单对象属性过滤现则器
- Courses