bus_mysql_to_hdfs.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. . /opt/app/bi-app/energy/dayTask/config.sh
  3. if [ -n "$2" ] ;then
  4. echo "如果是输入的日期按照取输入日期"
  5. do_date=$2
  6. else
  7. echo "====没有输入数据的日期,取当前时间的前一天===="
  8. do_date=$(date -d yesterday +"%Y-%m-%d")
  9. fi
  10. SAGA_DATABASE=sagacloud_customization
  11. url=$SAGA_URL_PRE$SAGA_DATABASE$SAGA_URL_SUF
  12. username=$SAGA_USER
  13. password=$SAGA_PASSWORD
  14. echo "$do_date"
  15. mysql_to_hdfs_lzo() {
  16. sqoop import \
  17. -D mapred.job.queue.name=default \
  18. --connect "$1" \
  19. --username "$2" \
  20. --password "$3" \
  21. --target-dir "$4""$7"/"$do_date" \
  22. --delete-target-dir \
  23. --columns "$5" \
  24. --query "$6 and \$CONDITIONS" \
  25. --num-mappers 1 \
  26. --hive-drop-import-delims \
  27. --fields-terminated-by '\001' \
  28. --compress \
  29. --compression-codec lzo \
  30. --hive-import \
  31. --hive-database saga_dw \
  32. --hive-table "$7" \
  33. --hive-overwrite \
  34. --hive-partition-key dt \
  35. --hive-partition-value "$do_date" \
  36. --null-string '\\N' \
  37. --null-non-string '\\N'
  38. }
  39. ## 空调操作记录表
  40. ods_feedback(){
  41. mysql_to_hdfs_lzo "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/ \
  42. "id, project_id, object_id, source_type, user_id, user_phone, user_name, value_type, item_id, value, create_time, next_open_time, model, duration_type, custom_plan, curr_temp, nick_name, result, exe_result, fb_temp, remark" \
  43. "select id, project_id, object_id, source_type, user_id, user_phone, user_name, value_type, item_id, value, create_time, next_open_time, model, duration_type, custom_plan, curr_temp, nick_name, result, exe_result, fb_temp, remark from feedback where date_format(create_time, '%Y-%m-%d') = '$do_date' and 1 = 1 " \
  44. ods_bus_feedback
  45. }
  46. case $1 in
  47. "all")
  48. ods_feedback
  49. ;;
  50. "ods_feedback")
  51. ods_feedback
  52. ;;
  53. esac