#! /bin/bash

source ../dmp_env.sh

COUNTRY=$1

PLATFORM=$2

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

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

ADN_REQUEST_INPUT_PATH=${ID_MAPPING}/${date_path}/adn_request

DSP_INPUT_PATH=${ID_MAPPING}/${date_path}/dsp_req

# check_await "${ADN_REQUEST_INPUT_PATH}/$PLATFORM/_SUCCESS"

# check_await "${DSP_INPUT_PATH}/$PLATFORM/_SUCCESS"

OUTPUT_PATH=${ADS_DEVICE_ID_MAPPING}/${date_path}/${COUNTRY}/${PLATFORM}

spark-submit --class mobvista.dmp.datasource.id_mapping.IDMappingGraphx \
  --name "IDMappingGraphx.${LOG_TIME}.${COUNTRY}.${PLATFORM}" \
  --conf spark.yarn.executor.memoryOverhead=2048 \
  --conf spark.network.timeout=720s \
  --conf spark.sql.shuffle.partitions=10000 \
  --conf spark.default.parallelism=10000 \
  --master yarn --deploy-mode cluster --executor-memory 10g --driver-memory 6g --executor-cores 5 --num-executors 200 \
  ../${JAR} -date ${LOG_TIME} -country ${COUNTRY} -platform ${PLATFORM} \
  -output ${OUTPUT_PATH}/mid -fre_output ${OUTPUT_PATH}/frequency -result_output ${OUTPUT_PATH}/result -coalesce 1000

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