123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #!/bin/bash
- . /opt/app/bi-app/energy/dayTask/config.sh
- if [ -n "$2" ] ;then
- echo "如果是输入的日期按照取输入日期"
- do_date=$2
- else
- echo "====没有输入数据的日期,取当前时间的前一天===="
- do_date=$(date -d yesterday +"%Y-%m-%d")
- fi
- SAGA_DATABASE=sagacloud_customization
- url=$SAGA_URL_PRE$SAGA_DATABASE$SAGA_URL_SUF
- username=$SAGA_USER
- password=$SAGA_PASSWORD
- echo "$do_date"
- mysql_to_hdfs_lzo() {
- sqoop import \
- -D mapred.job.queue.name=default \
- --connect "$1" \
- --username "$2" \
- --password "$3" \
- --target-dir "$4""$7"/"$do_date" \
- --delete-target-dir \
- --columns "$5" \
- --query "$6 and \$CONDITIONS" \
- --num-mappers 1 \
- --hive-drop-import-delims \
- --fields-terminated-by '\001' \
- --compress \
- --compression-codec lzo \
- --hive-import \
- --hive-database saga_dw \
- --hive-table "$7" \
- --hive-overwrite \
- --hive-partition-key dt \
- --hive-partition-value "$do_date" \
- --null-string '\\N' \
- --null-non-string '\\N'
- }
- mysql_to_hdfs_lzo_no_partition() {
- sqoop import \
- -D mapred.job.queue.name=default \
- --connect "$1" \
- --username "$2" \
- --password "$3" \
- --target-dir "$4""$7" \
- --delete-target-dir \
- --columns "$5" \
- --query "$6 and \$CONDITIONS" \
- --num-mappers 1 \
- --hive-drop-import-delims \
- --fields-terminated-by '\001' \
- --compress \
- --compression-codec lzo \
- --hive-import \
- --hive-database saga_dw \
- --hive-table "$7" \
- --hive-overwrite \
- --null-string '\\N' \
- --null-non-string '\\N'
- }
- ## 空调操作记录表
- ods_feedback(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/ \
- "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" \
- "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 " \
- ods_bus_feedback
- }
- ods_feedback_tmp(){
- mysql_to_hdfs_lzo_no_partition "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/ \
- "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" \
- "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 1 = 1 " \
- ods_bus_feedback_tmp
- }
- # 照明操作记录
- ods_light_switch(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/ \
- "id, project_id, object_id, source_type, user_id, user_phone, user_name, on_off, result, create_time, exe_result" \
- "select id, project_id, object_id, source_type, user_id, user_phone, user_name, on_off, result, create_time, exe_result from light_switch where date_format(create_time, '%Y-%m-%d') = '$do_date' and 1 = 1 " \
- ods_bus_light_switch
- }
- ods_light_switch_tmp(){
- mysql_to_hdfs_lzo_no_partition "$url" "$username" "$password" /warehouse/saga_dw/ods/tmp/ \
- "id, project_id, object_id, source_type, user_id, user_phone, user_name, on_off, result, create_time, exe_result" \
- "select id, project_id, object_id, source_type, user_id, user_phone, user_name, on_off, result, create_time, exe_result from light_switch where 1 = 1 " \
- ods_bus_light_switch_tmp
- }
- case $1 in
- "all")
- ods_feedback
- ods_light_switch
- ;;
- "ods_feedback")
- ods_feedback
- ;;
- "ods_feedback_tmp")
- ods_feedback_tmp
- ;;
- "ods_light_switch")
- ods_light_switch
- ;;
- "ods_light_switch_tmp")
- ods_light_switch_tmp
- ;;
- esac
|