data_new_table.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. set -x
  3. source /root/anaconda3/bin/activate py37
  4. export SPARK_HOME=/opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8
  5. export PATH=$SPARK_HOME/bin:$PATH
  6. export HADOOP_CONF_DIR=/etc/taihao-apps/hadoop-conf
  7. export JAVA_HOME=/usr/lib/jvm/java-1.8.0
  8. # nohup sh handle_rov.sh > "$(date +%Y%m%d_%H%M%S)_handle_rov.log" 2>&1 &
  9. # 原始数据table name
  10. table='alg_recsys_sample_all_v2'
  11. # 处理分区配置 推荐数据间隔一天生产,所以5日0点使用3日0-23点数据生产new模型数据
  12. begin_early_2_Str="20240728"
  13. end_early_2_Str="20240728"
  14. beginHhStr=00
  15. endHhStr=23
  16. max_hour=05
  17. max_minute=00
  18. # 各节点产出hdfs文件绝对路径
  19. # 源数据文件
  20. originDataPath=/dw/recommend/model/41_recsys_sample_data_v3/
  21. # 特征分桶
  22. bucketDataPath=/dw/recommend/model/43_recsys_train_data_v3/
  23. # hadoop
  24. HADOOP=/opt/apps/HADOOP-COMMON/hadoop-common-current/bin/hadoop
  25. # 0 判断上游表是否生产完成,最长等待到max_hour点
  26. # shellcheck disable=SC2154
  27. echo "$(date +%Y-%m-%d_%H-%M-%S)----------step0------------开始校验是否生产完数据,分区信息:beginStr:${begin_early_2_Str}${beginHhStr},endStr:${end_early_2_Str}${endHhStr}"
  28. while true; do
  29. python_return_code=$(python /root/joe/recommend-emr-dataprocess/qiaojialiang/checkHiveDataUtil.py --table ${table} --beginStr ${begin_early_2_Str}${beginHhStr} --endStr ${end_early_2_Str}${endHhStr})
  30. echo "python 返回值:${python_return_code}"
  31. if [ $python_return_code -eq 0 ]; then
  32. echo "Python程序返回0,校验存在数据,退出循环。"
  33. break
  34. fi
  35. echo "Python程序返回非0值,不存在数据,等待五分钟后再次调用。"
  36. sleep 300
  37. current_hour=$(date +%H)
  38. current_minute=$(date +%M)
  39. # shellcheck disable=SC2039
  40. if (( current_hour > max_hour || (current_hour == max_hour && current_minute >= max_minute) )); then
  41. echo "最长等待时间已到,失败:${current_hour}-${current_minute}"
  42. /root/anaconda3/bin/python monitor_util.py --level error --msg "荐模型数据更新 \n【任务名称】:step0校验是否生产完数据\n【是否成功】:error\n【信息】:最长等待时间已到,失败:${current_hour}-${current_minute}"
  43. exit 1
  44. fi
  45. done
  46. # 1 生产原始数据
  47. echo "$(date +%Y-%m-%d_%H-%M-%S)----------step1------------开始根据${table}生产原始数据"
  48. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  49. --class com.aliyun.odps.spark.examples.makedata_recsys.makedata_recsys_41_originData_20240709 \
  50. --master yarn --driver-memory 1G --executor-memory 2G --executor-cores 1 --num-executors 16 \
  51. ../target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  52. tablePart:64 repartition:32 \
  53. beginStr:${begin_early_2_Str}00 endStr:${end_early_2_Str}09 \
  54. savePath:${originDataPath} \
  55. table:${table} &
  56. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  57. --class com.aliyun.odps.spark.examples.makedata_recsys.makedata_recsys_41_originData_20240709 \
  58. --master yarn --driver-memory 1G --executor-memory 2G --executor-cores 1 --num-executors 16 \
  59. ../target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  60. tablePart:64 repartition:32 \
  61. beginStr:${begin_early_2_Str}10 endStr:${end_early_2_Str}15 \
  62. savePath:${originDataPath} \
  63. table:${table} &
  64. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  65. --class com.aliyun.odps.spark.examples.makedata_recsys.makedata_recsys_41_originData_20240709 \
  66. --master yarn --driver-memory 1G --executor-memory 2G --executor-cores 1 --num-executors 16 \
  67. ../target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  68. tablePart:64 repartition:32 \
  69. beginStr:${begin_early_2_Str}16 endStr:${end_early_2_Str}23 \
  70. savePath:${originDataPath} \
  71. table:${table} &
  72. wait
  73. if [ $? -ne 0 ]; then
  74. echo "Spark原始样本生产任务执行失败"
  75. /root/anaconda3/bin/python monitor_util.py --level error --msg "荐模型数据更新 \n【任务名称】:step1根据${table}生产原始数据\n【是否成功】:error\n【信息】:Spark原始样本生产任务执行失败"
  76. exit 1
  77. else
  78. echo "spark原始样本生产执行成功"
  79. fi
  80. # 2 特征分桶
  81. echo "$(date +%Y-%m-%d_%H-%M-%S)----------step2------------根据特征分桶生产重打分特征数据"
  82. /opt/apps/SPARK2/spark-2.4.8-hadoop3.2-1.0.8/bin/spark-class2 org.apache.spark.deploy.SparkSubmit \
  83. --class com.aliyun.odps.spark.examples.makedata_recsys.makedata_recsys_43_bucketData_20240709 \
  84. --master yarn --driver-memory 2G --executor-memory 4G --executor-cores 1 --num-executors 16 \
  85. ../target/spark-examples-1.0.0-SNAPSHOT-shaded.jar \
  86. readPath:${originDataPath} \
  87. savePath:${bucketDataPath} \
  88. beginStr:${begin_early_2_Str} endStr:${end_early_2_Str} repartition:500 \
  89. filterNames:XXXXXXXXX \
  90. fileName:20240609_bucket_314.txt \
  91. whatLabel:is_return whatApps:0,4,21,17
  92. if [ $? -ne 0 ]; then
  93. echo "Spark特征分桶处理任务执行失败"
  94. /root/anaconda3/bin/python monitor_util.py --level error --msg "荐模型数据更新 \n【任务名称】:step3训练数据产出\n【是否成功】:error\n【信息】:Spark特征分桶处理任务执行失败"
  95. exit 1
  96. else
  97. echo "spark特征分桶处理执行成功"
  98. fi
  99. echo "$(date +%Y-%m-%d_%H-%M-%S)----------step5------------spark特征分桶处理执行成功:${begin_early_2_Str}"