#!/bin/bash

# # # # # # # # # # # # # # # # # # # # # #
# @author : wangjf
# @date : 2019-08-28 17:39:26
# @desc : 将ali interest并到安装列表
# # # # # # # # # # # # # # # # # # # # # #

source ../dmp_env.sh

LOG_TIME=$(date -d "$ScheduleTime" "+%Y%m%d")
year=${LOG_TIME:0:4}
month=${LOG_TIME:4:2}
day=${LOG_TIME:6:2}

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

business='ali'
INPUT_INSTALL_PATH="${DM_INSTALL_LIST}/$year/$month/$day/${business}"

BEFORE_TIME=$(date -d "$ScheduleTime 1 days ago" +"%Y%m%d")
before_date_path=$(date -d "$ScheduleTime 1 days ago" +"%Y/%m/%d")

INPUT_APP_TAG_PATH="${APP_TAG_PATH}/${before_date_path}"

OUTPUT_PATH="${DM_INTEREST_PATH}/${year}/${month}/${day}/${business}"

check_await "${INPUT_APP_TAG_PATH}/_SUCCESS"

# REDUCE_NUM=$(calculate_reduce_num ${INPUT_INSTALL_PATH})
REDUCE_NUM=400

hadoop fs -rm -r ${OUTPUT_PATH}
hadoop jar ../${JAR} mobvista.dmp.common.InterestDeviceDistinctMR \
    -Dmapreduce.fileoutputcommitter.algorithm.version=2 \
    -Dmapreduce.map.memory.mb=4096 \
    -Dmapreduce.map.java.opts=-Xmx2458m \
    -Dmapreduce.reduce.memory.mb=4096 \
    -Dmapreduce.reduce.java.opts=-Xmx2458m \
    -Dmapreduce.job.reduces=${REDUCE_NUM} \
    "${INPUT_APP_TAG_PATH}/part-r-00000" "${INPUT_INSTALL_PATH}" "${OUTPUT_PATH}" "ali interest job"

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

mount_partition "dm_interest_tag" "year='$year', month='$month', day='$day', business='${business}'" "$OUTPUT_PATH"

echo "[ali Interest Tag End!]"
