DataX 动态传参

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "hdfsreader", 
                    "parameter": {
                        "column": [
                               {
                                "index": 0,
                                "type": "string"
                               },
                               {
                                "index": 1,
                                "type": "string"
                               },
                               {
                                "index": 2,
                                "type": "string"
                               },
                               {
                                "index": 3,
                                "type": "string"
                               },
                               {
                                "type": "string",
                                "value": "$DT"
                               },
                               {
                                "type": "string",
                                "value": "$DN"
                               }
                        ], 
                        "defaultFS": "hdfs://hadoop102:9000", 
                        "encoding": "UTF-8", 
                        "fieldDelimiter": "\t", 
                        "fileType": "text", 
                        "path": "/user/hive/warehouse/ads.db/ads_paper_scoresegment_user/dt=${DT}/dn=$DN"
                    }
                }, 
                "writer": {
                    "name": "mysqlwriter", 
                    "parameter": {
                        "column": ["*"], 
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:mysql://hadoop102:3306/datax", 
                                "table": ["ads_paper_scoresegment_user"]
                            }
                        ], 
                        "password": "123456", 
                        "username": "root", 
                        "writeMode": "insert"
                    }
                }
            }
        ], 
        "setting": {
            "speed": {
                "channel": "1"
            }
        }
    }
}

在实际应用当中,往往会需要动态传入分区字段,那么在json文件中,可以选择${参数值}来进行传参 相应的在执行命令上 使用-p “ -D参数值” 进行传参

#!/bin/bash
DT="$1"
DN="$2"
python /opt/module/datax/bin/datax.py -p "-DDT=${DT} -DDN=${DN}" \
/opt/module/datax/job/datawarehouse/ads_paper_avgtimeandscore.json

你可能感兴趣的:(DataX 动态传参)