datax的json中写参数
时间: 2024-01-10 14:20:17 浏览: 297
在datax的中,可以使用${}来引用参数。其中,参数可以在命令行中使用-p参数传递,也可以在job.json文件中定义。下面是一个示例:
```json
{
"job": {
"setting": {
"speed": {
"channel": 3
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "${username}",
"password": "${password}",
"column": [
"id",
"name"
],
"where": "id > ${min_id} and id < ${max_id}"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"username": "${username}",
"password": "${password}",
"column": [
"id",
"name"
],
"preSql": "delete from test where id > ${min_id} and id < ${max_id}",
"connection": [
{
"jdbcUrl": "jdbc:mysql://localhost:3306/test",
"table": [
"test"
]
}
]
}
}
}
]
}
}
```
在上面的示例中,可以看到where属性中使用了${min_id}和${max_id}两个参数。这两个参数可以在命令行中使用-p参数传递,例如:
```shell
nohup /usr/bin/python2 ${DATAX_PATH}/datax.py -p "-Dmin_id=100 -Dmax_id=200" job.json &
```
也可以在job.json文件中定义,例如:
```json
{
"job": {
"setting": {
"speed": {
"channel": 3
}
},
"content": [
{
"reader": {
"name": "mysqlreader",
"parameter": {
"username": "${username}",
"password": "${password}",
"column": [
"id",
"name"
],
"where": "id > ${min_id} and id < ${max_id}"
}
},
"writer": {
"name": "mysqlwriter",
"parameter": {
"username": "${username}",
"password": "${password}",
"column": [
"id",
"name"
],
"preSql": "delete from test where id > ${min_id} and id < ${max_id}",
"connection": [
{
"jdbcUrl": "jdbc:mysql://localhost:3306/test",
"table": [
"test"
]
}
]
}
}
}
]
},
"jobExtendInfo": {
"min_id": 100,
"max_id": 200
}
}
```
在上面的示例中,可以看到job.json文件中定义了min_id和max_id两个参数。这两个参数可以在命令行中不传递,datax会自动读取job.json文件中的定义。如果命令行中传递了-p参数,则会覆盖job.json文件中的定义。
阅读全文