hivef:hive 執行 sql 文件


hivef:hive 執行 sql 文件

#!/bin/bash

yesterday=`date -d -1days '+%Y-%m-%d'`
today=`date '+%Y-%m-%d'`
tomarrow=`date -d 1days '+%Y-%m-%d'`

#echo "從外部只傳遞兩個參數時,第一個參數必須是 hive sql 文件,第二個必須是YYYY-MM-DD格式的日期!"
#echo "從外部只傳遞一個參數時,第一個參數必須是 hive sql 文件"

if [ $# == 2 ]; then
   sqlfile=$1
   echo "從外部只傳遞兩個參數時,第一個參數必須是 hive sql 文件,第二個必須是YYYY-MM-DD格式的日期!"
   if [ $2 == "1970-01-01" ]; then
      ## 正常調度時,real 作業的日期是當天,但是依賴 real 作業的離線作業的日期是前一天
      if [[ $sqlfile == *"real.sql"* ]]; then
         echo "定時調度運行real 作業時,只需要一個sql文件作為參數,日期默認取當天"
         dt=$today
      else
         echo "正常調度時,real 作業的日期是當天,但是依賴 real 作業的離線作業的日期是前一天"
         dt=$yesterday
      fi
   elif [[ $2 =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] && date -d "$2" >/dev/null
      then echo "Date $2 is valid and matches the format (YYYY-MM-DD)"
      echo "手動運行的時候,第二個參數為日期,需要手動指定,格式: YYYY-MM-DD"
      dt=$2
   else
      echo "Date $2 not matches the format (YYYY-MM-DD)!"
      exit 11
   fi
else
   echo "無法識別的參數!"
   exit 11
fi

echo "===>> 當前sql: $sqlfile, 執行日期: $dt"

hive \
-d yesterday=$yesterday -d date=$dt -d tomarrow=$tomarrow \
-f $sqlfile \
-i hdfs://emr-header-1.cluster-70637:9000/dw/hive_udf/hive_udf_init.hql

if test $? -ne 0
then
exit 11
fi


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM