<>前言

大数据项目上的一个小功能实现,需要将现有天数据表中的数据求和,得到月数据表
供页面展示,干脆直接dataX推送数据实现,读取mysql(使用sql聚合查询计算),并写入mysql,可以当做模板进行修改并使用。详细的.sh可执行文件 以及
.json文件 如下

* month.sh脚本执行文件
#使用dataX推送计算后的mysql数据(sql聚合函数)到mysql的---t_area_month_passenger #! /bin/bash
source /etc/profile YEAR=`date +%Y -d '-1 hours'` MONTH=`date +%m -d '-1 hours'`
#定义月数,于month.json中取上一个月的数字 if [MONTH -eq 1]; then YEAR=YEAR-1 MONTH=13 else
MONTH=`date +%m -d '-1 hours'` fi full='t_area_month_passenger' python
/root/datax/bin/datax.py -p"-DYEAR=${YEAR} -DTABLE=${full} -DMONTH=${MONTH}"
/root/datax/job/month.json>/root/datax/bin/month.log 2>&1 &
* month.json配置文件 { "core":{ "transport":{ "channel":{ "speed":{ "record"
:10000,"byte":1000000 } } } }, "job": { "setting": { "speed": { "record":5000,
"byte":100000, "channel": 1 } }, "content": [{ "reader": { "name": "mysqlreader"
,"parameter": { "username": "root", "password": "developer@lydsj", "connection":
[{ "querySql": [ "select area_id,sum(value) as value,year,month,2 as type from
t_area_day_passenger where year=${YEAR} and month=${MONTH}-1 GROUP BY area_id;"
], "jdbcUrl": [
"jdbc:mysql://172.22.1.99:3306/sms_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false"
] }] } }, "writer": { "name": "mysqlwriter", "parameter": { "writeMode":"insert"
,"username":"root", "password":"developer@lydsj", "column":[ "AREA_ID", "value",
"year", "month", "type" ], "connection":[ { "jdbcUrl":
"jdbc:mysql://172.22.1.99:3306/sms_server?useUnicode=true&characterEncoding=UTF-8&useSSL=false"
,"table":[ "${TABLE}" ] } ] } } }] } }
<>tips:

* 1.tips:json文件写好后,可先网页进行json格式校验
* 2.在dataX的reader配置时,不能同时配置“querySql”和“table”项,否则会报以下错误: 您配置凌乱了.
不能同时既配置table又配置querySql

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信