【HIVE】hive 使用shell指令碼跑歷史資料

Zsigner發表於2020-12-31

背景:補充分割槽表歷史資料,寫了個shell指令碼

 

指令碼程式碼:

vall=(20191201 20191224 20191225 20191226 20191227 20191228 20191229 20191230 20191231 20200101 20200102 20200103 20200104 20200105 20200106 20200107 20200108 20200109 20200110 20200111 20200112 20200113 20200114 20200115 20200116 20200117 20200118 20200119 20200120 20200121 20200122 20200123 20200124 20200125 20200126 20200127 20200128 20200129 )


 for i in $(seq 0 ${#vall[@]}); do

#${val[$i]}

  echo ${vall[$i]}
  cresql='CREATE TABLE IF NOT EXISTS db_test.test_shop_d LIKE db_result.shop_d;'
  echo ${cresql}
  altsql='ALTER TABLE db_test.test_shop_d DROP IF EXISTS PARTITION(statdate='${vall[$i]}');'
  echo ${altsql}

  inssql='INSERT INTO TABLE  db_test.test_shop_d PARTITION(statdate='${vall[$i]}') (app_id, account_active_value,income_30,active_day_7,order_active_value,active_state,order_count_7_score,active_user_7_score,pay_user_30,shop_name,compare_7_rate,total_score,existence_day,user_score,first_sd_time,goods_count_30_score,account_score,income_30_score,active_day_7_score,order_count_7,active_user_7,order_score,app_created_at,pay_user_30_score,compare_30_rate,total_active_value,day,user_active_value,expire_time,version,goods_count_30) SELECT md5(concat("test",app_id)) as app_id, account_active_value,income_30,active_day_7,order_active_value,active_state,order_count_7_score,active_user_7_score,pay_user_30,shop_name,compare_7_rate,total_score,existence_day,user_score,first_sd_time,goods_count_30_score,account_score,income_30_score,active_day_7_score,order_count_7,active_user_7,order_score,app_created_at,pay_user_30_score,compare_30_rate,total_active_value,day,user_active_value,expire_time,version,goods_count_30 FROM db_result.shop_d WHERE statdate='${vall[$i]}' ;'
echo ${inssql}
hive -e  "${cresql} ${altsql} ${inssql}"
done

 

相關文章