1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #!/bin/bash
- . /usr/local/service/sagaApps/bi_saga/dwh_saga/task_day/config.sh
- if [ -n "$2" ] ;then
- do_date=$2
- else
- echo "====没有输入数据的日期,取当前时间的前一天===="
- do_date=$(date -d yesterday +"%Y-%m-%d")
- fi
- url=$MYSQL_URL
- username=$MYSQL_USER
- password=$MYSQL_PASSWORD
- mysql_to_hdfs_lzo() {
- /usr/local/service/sqoop/bin/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'
- }
- ## 能源 15 分钟差值
- ods_energy_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, from_unixtime(unix_timestamp(data_time) + 28800) as data_time, data_value from energy_15_min where 1 = 1 " ods_energy_15_min
- }
- ## CO2 15 分钟分精度
- ods_co2_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, data_time, data_value from co2_15_min where dt = '$do_date'" ods_co2_15_min
- }
- ## PM2.5 15 分钟分精度
- ods_pm25_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, data_time, data_value from pm25_15_min where dt = '$do_date'" ods_pm25_15_min
- }
- ## 甲醛 15 分钟分精度
- ods_hcho_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, data_time, data_value from hcho_15_min where dt = '$do_date'" ods_hcho_15_min
- }
- ## 温度 15 分钟分精度
- ods_temperature_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, data_time, data_value from temperature_15_min where dt = '$do_date'" ods_temperature_15_min
- }
- ## 湿度 15 分钟分精度
- ods_humidity_15_min(){
- mysql_to_hdfs_lzo "$url" "$username" "$password" /saga/saga_dw/ods/tmp/ "building, func_id, meter, data_time, data_value" "select building, func_id, meter, data_time, data_value from humidity_15_min where dt = '$do_date'" ods_humidity_15_min
- }
- case $1 in
- "all")
- ods_energy_15_min
- ods_co2_15_min
- ods_pm25_15_min
- ods_hcho_15_min
- ods_temperature_15_min
- ods_humidity_15_min
- ;;
- "ods_energy_15_min")
- ods_energy_15_min
- ;;
- "ods_co2_15_min")
- ods_co2_15_min
- ;;
- "ods_pm25_15_min")
- ods_pm25_15_min
- ;;
- "ods_hcho_15_min")
- ods_hcho_15_min
- ;;
- "ods_temperature_15_min")
- ods_temperature_15_min
- ;;
- "ods_humidity_15_min")
- ods_humidity_15_min
- ;;
- esac
|