前言
大数据项目上的一个小功能实现,需要将现有天数据表中的数据求和,得到月数据表供页面展示,干脆直接dataX推送数据实现,读取mysql(使用sql聚合查询计算),并写入mysql,可以当做模板进行修改并使用。详细的 .sh可执行文件 以及 .json文件 如下
source /etc/profile
YEAR=`date +%Y -d '-1 hours'`
MONTH=`date +%m -d '-1 hours'`
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 &
{
"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
|