sparkf:spark-sql替換hive查詢引擎
CONSOLE# WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
hive 查詢的時候經常會提醒這一句,那就改成 spark-sql 吧。哦彌陀佛~~
spark-sql
#!/bin/bash
. /etc/profile
yesterday=`date -d -1days '+%Y-%m-%d'`
echo "yesterday,(format :yyyy-MM-dd):"$yesterday
today=`date '+%Y-%m-%d'`
echo "today,(format :yyyy-MM-dd):"$today
tomarrow=`date -d 1days '+%Y-%m-%d'`
echo "tomarrow,(format :yyyy-MM-dd):"$tomarrow
hour_nowk=`date '+%k'`
echo "hour_now,(format %k:0-23):"$hour_nowk
hour_nowH=`date '+%H'`
echo "hour_now,(format %H:00-23):"$hour_nowH
hour_agok=`date -d -1hours '+%k'`
echo "hour_ago,(format %k:0-23):"$hour_agok
hour_agoH=`date -d -1hours '+%H'`
echo "hour_ago,(format %H:00-23):"$hour_agoH
#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"
spark-sql \
--queue bi \
--name dw_etl_$dt \
-d date=$dt \
-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