#!/usr/bin/env bash


source ../../dmp_env.sh

dt_today=$(date -d "$ScheduleTime 1 days ago" +"%Y%m%d")
yesterday=$(date -d "$ScheduleTime 2 days ago" +"%Y%m%d")

dt_slash_today=$(date -d "$ScheduleTime 1 days ago" +"%Y/%m/%d")
dt_dash_today=$(date -d "$ScheduleTime 1 days ago" +"%Y-%m-%d")
last_req_day=$(date -d "$ScheduleTime 180 days ago" +"%Y-%m-%d")
dt_dash_rec14day=$(date -d "$ScheduleTime 15 days ago" +"%Y-%m-%d")


ALI_OAID_OUTPUT_DAILY_PATH="${ALI_OAID_USER_ACTIVATION_DAILY_PATH}/${dt_slash_today}"
OUTPUT_PATH="${ALI_OAID_USER_ACTIVATION_15DAYS_PATH}/${dt_slash_today}"

check_await "${ODS_DMP_USER_INFO}/${dt_slash_today}/adn_request/_SUCCESS"
check_await "${ODS_DMP_USER_INFO}/${dt_slash_today}/dsp_req/_SUCCESS"

hadoop fs -rm -r "$OUTPUT_PATH"
hadoop fs -rm -r "$ALI_OAID_OUTPUT_DAILY_PATH"
hadoop fs -rm -r "${OAID_REQUEST_COUNT_RESULT}/${dt_today}"

spark-submit --class mobvista.dmp.datasource.taobao.EtlAliOaidActivitionDaily \
 --conf spark.network.timeout=720s \
 --conf spark.default.parallelism=2200 \
 --conf spark.sql.shuffle.partitions=2200 \
 --conf spark.sql.broadcastTimeout=1200 \
 --conf spark.yarn.executor.memoryOverhead=4096 \
 --conf spark.sql.autoBroadcastJoinThreshold=31457280 \
 --deploy-mode cluster  --executor-memory 10g --driver-memory 4g  --executor-cores 4  --num-executors 60 \
 ../../${JAR} -output ${OUTPUT_PATH} -outputdaily ${ALI_OAID_OUTPUT_DAILY_PATH} -coalesce 500 \
 -yesterday ${yesterday} -today ${dt_today}  -dt_dash_today ${dt_dash_today} -dt_dash_rec14day ${dt_dash_rec14day} \
 -request_count_result "${OAID_REQUEST_COUNT_RESULT}/${dt_today}" -last_req_day ${last_req_day}


if [ $? -ne 0 ];then
  exit 255
fi

mount_partition "ali_oaid_user_activation_daily" "dt='${dt_today}'" "$ALI_OAID_OUTPUT_DAILY_PATH"
mount_partition "ali_oaid_user_activation_rec15days" "dt='${dt_today}'" "$OUTPUT_PATH"


###  数据上传到oss文件系统

hadoop fs -touchz $ALI_OAID_OUTPUT_DAILY_PATH/_SUCCESS
hadoop fs -touchz $OUTPUT_PATH/_SUCCESS

