hive自動(dòng)化load數(shù)據(jù)到表

#!/bin/bash
. /etc/profile
. ~/.bash_profile
. ~/.bashrc


error() {
       if [[ $? != 0 ]]; then
       echo "$@  運(yùn)行失敗"
       exit 1
       fi
}

# 待上傳表名
inset_table_name=$1
# 待上傳文件名
file_name=$2
# 分區(qū)名
pt=$3
load_path="/dz/load_path/"

curr_date=`date +%F|sed 's/-//g'`

eg_sql="
create table  tmp.xx_xxx_${curr_date}
(
filed_list string 
,label_one string 
)partitioned by (pt string comment 'YYMMDD數(shù)據(jù)入庫時(shí)間')
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS textfile
"

if [[ $1 = "help" ]];then 
   echo -e "\033[40;31m   追加寫入分區(qū)表 :入?yún)⑴渲?4個(gè)參數(shù):待上傳表名+待上傳文件名+分區(qū)名 + 1 [第四個(gè)參數(shù)為1,表示追加]  \033[0m"
   echo "ds_load upload_table file_name pt 1"
   echo -e "\033[40;31m   覆蓋寫入分區(qū)表 :入?yún)⑴渲?3個(gè)參數(shù):待上傳表名+待上傳文件+分區(qū)名【不能為數(shù)字1】 \033[0m"
   echo "ds_load upload_table file_name pt"
   echo -e "\033[40;31m   追加寫入非分區(qū)表 :入?yún)⑴渲?3個(gè)參數(shù):待上傳表名+待上傳文件 + 1【數(shù)字1,表示追加】 \033[0m"
   echo "ds_load upload_table file_name 1"
   echo -e "\033[40;31m   覆蓋寫入非分區(qū)表 :入?yún)⑴渲?2個(gè)參數(shù):待上傳表名+待上傳文件  \033[0m"
   echo "ds_load upload_table file_name"
   echo "建表語句樣例:${eg_sql}"
   exit 0
fi 

if [[ $# < 2 ]];then 
  echo "參數(shù)個(gè)數(shù)有問題,請(qǐng)使用ds_load help 查看用法"
  exit 0
fi



hadoop fs -put ${file_name} ${load_path}${file_name}
error "上傳失敗,請(qǐng)檢查HDFS目錄,刪除失敗文件"

load_sql_pt_into="load data inpath '${load_path}${file_name}'  into table ${inset_table_name} partition(pt='${pt}')"

load_sql_pt="load data inpath '${load_path}${file_name}' overwrite  into table ${inset_table_name} partition(pt='${pt}')"

load_sql_into="load data inpath '${load_path}${file_name}'   into table ${inset_table_name} "

load_sql_ow="load data inpath '${load_path}${file_name}' overwrite  into table ${inset_table_name} "


#  追加寫入分區(qū)表
if [[ $# = 4  ]] && [[ $4 = 1 ]];then 
  sh ~/bee_u_e.sh "${load_sql_pt_into}"
  error  "上傳"
  echo "上傳成功"
# 覆蓋寫入分區(qū)表,分區(qū)名不能為1
elif [[  $# = 3 ]] && [[ $3 != 1 ]];then
  sh ~/bee_u_e.sh "${load_sql_pt}"
  error  "上傳"
  echo "上傳成功"
# 追加寫入非分區(qū)表
elif [[  $# = 3 ]] && [[ $3 = 1 ]];then
  sh ~/bee_u_e.sh "${load_sql_into}"
  error  "上傳"
  echo "上傳成功"
# 覆蓋寫入分區(qū)表
elif [[ $# = 2 ]];then 
  sh ~/bee_u_e.sh "${load_sql_ow}"
  error  "上傳"
  echo "上傳成功"
else 
  echo "請(qǐng)檢查參數(shù)個(gè)數(shù)"
  echo -e "\033[40;31m 使用ds_load help 查看用法 \033[0m"
  exit 0
fi


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容