引言:
上一篇文章《sqoop1.4.4 实现将 oracle10g 中的增量数据导入 hive0.13.1 ,,并更新hive中的主表
shell脚本
#!/bin/bash
#please set the synchronize interval,unit is hour.
update_interval=24
#please set the rdbms connection params
rdbms_connstr=jdbc:oracle:thin:@192.168.0.147:1521:orclgbk
rdbms_username=sp
rdbms_pwd=fulong
rdbms_table=omp_service
rdbms_columns=id,service_name,service_process,create_time,enable_org,enable_platform,if_del
#please set the hive params
hive_increment_table=service_tmp
hive_full_table=service_all
#---------------------------------------------------------
#import icrement data in rdbms into hive
enddate=$(date '+%y/%m/%d %h:%m:%s')
startdate=$(date '+%y/%m/%d %h:%m:%s' -d '-'+${update_interval}+' hours')
$sqoop_home/bin/sqoop import --connect ${rdbms_connstr} --username ${rdbms_username} --password ${rdbms_pwd} --table ${rdbms_table} --columns ${rdbms_columns} --where create_time > to_date('${startdate}','yyyy-mm-dd hh24:mi:ss') and create_time
#---------------------------------------------------------
#update the old full data table to latest status
$hive_home/bin/hive -e insert overwrite table ${hive_full_table} select * from ${hive_increment_table} union all select a.* from ${hive_full_table} a left outer join ${hive_increment_table} b on a.service_code = b.service_code where b.service_code is null;
注意:
在shell脚本中执行hive hql的命令格式是 hive -e select ...
cron脚本
添加定时任务每天凌晨2点执行该脚本
0 2 * * * /home/fulong/shell/datasync.sh
基于hadoop集群的hive安装
hive内表和外表的区别
hadoop + hive + map +reduce 集群安装部署
hive本地独立模式安装
hive学习之wordcount单词统计
hive运行架构及配置部署
hive 的详细介绍:请点这里
hive 的下载地址:请点这里
本文永久更新链接地址:
