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
原创粉丝点击