shell脚本加载数据文件到hive表中
来源:互联网 发布:做java培训讲师怎么样 编辑:程序博客网 时间:2024/04/30 21:24
如果执行时间允许,还可以增加判断hive表是否存在的。
#!/bin/ksh#-------------------------------------------------------------------------------------#---1、shell加载数据#---2、用hive_sql_handler调用写好的sql脚本#-------------------------------------------------------------------------------------DATE_YYYYMMDD=`date +%Y%m%d`conf_file='/home/xinxinghe/cfg/datafile.properties'tab_schema='temp'tab_fo017_reg="${tab_schema}.base_fo017_reg"tab_fo015_reg="${tab_schema}.base_fo015_reg"tab_fceso_reg="${tab_schema}.base_fceso_reg"tab_fo015_daily="${tab_schema}.base_fo015_active_daily"tab_fo015_monthly="${tab_schema}.base_fo015_active_monthly"dir_logfile="/home/xinxinghe/log/$(date +F)"###load_Data_to_Hive datafile tablenameload_Data_to_Hive(){ datafile=$1 tabname=$2 ###判断数据文件是否为有效文件 if [[ -f $datafile ]] then sqlstat="load data local inpath '${datafile}' overwrite into table ${tabname} partition (pt = '${DATE_YYYYMMDD}');" hive -e "$sqlstat" 1>> $log_file 2>> $log_file else echo "WARNING(Datafile ${datafile} not Exists)!" >> $log_file #exit fi}###begin###判断日志目录是否存在if [[ ! -d $dir_logfile ]]then mkdir -p $dir_logfilefilog_file="${dir_logfile}/job_f_user_reg_load_data_$(date +'%Y%m%d%H%M%S%5N')"###判断配置文件是否存在if [[ -f $conf_file ]]then continueelse echo "Configuration File $conf_file Not Exists!" >> $log_file exitfi###读取配置文件while read line || [[ -n $line ]] do typeset -L v1=$line typeset -R v2=$v1 line=$v2 if [[ ${#line} -ne 0 && ${line:0:1} != "#" ]] then prefix=${line%%=*} suffix=${line##*=} case $prefix in 'BASE_FO017_REG' ) file_fo017_reg=$suffix ;; 'BASE_FO015_REG' ) file_fo015_reg=$suffix ;; 'BASE_FCESO_REG' ) file_fceso_reg=$suffix ;; 'BASE_FO015_ACTIVE_DAILY' ) file_fo015_daily=$suffix ;; 'BASE_FO015_ACTIVE_MONTHLY' ) file_fo015_monthly=$suffix ;; 'DIR_NAME' ) dir_name=$suffix ;; esac fi done <"$conf_file"###绝对路径的数据文件变量file_fo017_reg="${dir_name}/${file_fo017_reg}"file_fo015_reg="${dir_name}/${file_fo015_reg}"file_fceso_reg="${dir_name}/${file_fceso_reg}"file_fo015_daily="${dir_name}/${file_fo015_daily}"file_fo015_monthly="${dir_name}/${file_fo015_monthly}"###加载数据echo "$file_fo017_reg $tab_fo017_reg" >> $log_fileecho "$file_fo015_reg $tab_fo015_reg" >> $log_fileecho "$file_fceso_reg $tab_fceso_reg" >> $log_fileecho "$file_fo015_daily $tab_fo015_daily" >> $log_fileecho "$file_fo015_monthly $tab_fo015_monthly" >> $log_file###加载数据到表中load_Data_to_Hive $file_fo017_reg $tab_fo017_regload_Data_to_Hive $file_fo015_reg $tab_fo015_regload_Data_to_Hive $file_fceso_reg $tab_fceso_regload_Data_to_Hive $file_fo015_daily $tab_fo015_dailyload_Data_to_Hive $file_fo015_monthly $tab_fo015_monthly###执行hive脚本#/data1/hive/wls81/bin/hive_sql_handler.ksh /data1/hive/wls81/sql/f_user_reg.sql hive /home/xinxinghe/sql/f_user_reg.sql -d DATABASE_RESULT='temp' DATABASE_FBD='fbd_orc' 1>>$log_file 2>>$log_file
0 0
- shell脚本加载数据文件到hive表中
- 数据文件数据加载到hive表
- 将外部数据文件导入到hive中
- 加载txt文件到Hive表中
- shell中上传数据文件到odps
- shell中循环调用hive sql 脚本
- 使用Python脚本从Hive中取数据计算后加载到Mysql示例
- 在Oozie 中调度执行shell、hive 脚本,以及通过shell脚本执行hive/sqoop/shell脚本的方法
- MapReduce产生RCFile文件在HDFS,HIve将RCFile文件加载到hive的表中
- 通过Load table命令将数据文件加载到Sybase IQ数据库里面的Python脚本
- Shell脚本执行Hive语句
- hive脚本+shell执行方式
- hive transform shell脚本运行
- HIVE的shell脚本模板
- 使用shell将hdfs上的数据导入到hive表中
- 从Oracle数据库中导入数据到Hive中的脚本
- Hive使用脚本加载数据
- 在初始化的过程中将一些数据文件加载到系统目录中
- Caffe1.0.0安装 编译 - Ubuntu 14.04
- 嵌入式系统编程风格的建立与学习
- linux下如何安装配置redis及主从配置
- 图片压缩、编辑、剪切
- 婚姻:多么庆幸,没有在最美丽的年华遇见你......
- shell脚本加载数据文件到hive表中
- 简单配置使用Redis
- java多线程之线程同步
- scala的类型系统
- 如何彻底删除hao123的桌面快捷方式
- BZOJ 3926: [Zjoi2015]诸神眷顾的幻想乡
- Spark统一内存管理模型UnifiedMemoryManager
- 负载均衡实现原理和方法
- Android内存泄露问题汇总