#! /bin/bash

source ../dmp_env.sh

LOG_TIME=$(date +%Y%m%d -d "-1 day $ScheduleTime")
date_path=$(date +'%Y/%m/%d' -d "-1 day $ScheduleTime")

# INPUT_PATH=${ETL_ADN_ORG_REQ_HOURS}/${date_path}

INPUT_PATH="s3://mob-emr-test/reyun/dmp/onedata/dwd/dwd_device_ids_inc_daily/${date_path}"

check_await "${INPUT_PATH}/tkio_event/ios/_SUCCESS"
check_await "${INPUT_PATH}/tkio_click/ios/_SUCCESS"
check_await "${INPUT_PATH}/abtest/ios/_SUCCESS"
check_await "${INPUT_PATH}/tkio_event/android/_SUCCESS"
check_await "${INPUT_PATH}/tkio_click/android/_SUCCESS"
check_await "${INPUT_PATH}/abtest/android/_SUCCESS"

BUSINESS="reyun"

OUTPUT_PATH=${ID_MAPPING}/${date_path}/${BUSINESS}

spark-submit --class mobvista.dmp.datasource.id_mapping.ReYun \
  --name "EtlDeviceIdDaily.$BUSINESS.$LOG_TIME" \
  --conf spark.yarn.executor.memoryOverhead=2048 \
  --conf spark.network.timeout=720s \
  --conf spark.sql.shuffle.partitions=5000 \
  --conf spark.default.parallelism=5000 \
  --deploy-mode cluster --executor-memory 12g --driver-memory 8g --executor-cores 5 --num-executors 100 \
  ../${JAR} -date ${LOG_TIME} -business ${BUSINESS} -output ${OUTPUT_PATH} -coalesce 1000

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