Skip to content
binaryWorld edited this page Jun 25, 2016 · 3 revisions

运行DataX作业动态传入参数

一、运行时传入参数 -p

    $ cd {YOUR_DATAX_DIR_BIN}
    $ python datax.py  -p "-Ddate=20160612 -Dhour=01" ./mysql2odps.json 

二、 JSON 作业中使用, $date $hour 即可,例如在odpswriter的参数中,"partition": "pt=$date"

   {
       "job": {
           "content": [
               {
                   "reader": {
                       "name": "mysqlreader",
                       "parameter": {
                           "username": "****",
                           "password": "****",
                           "column": ["id","age","name"],
                           "connection": [
                               {
                                   "table": [
                                       "test_table"
                                   ],
                                   "jdbcUrl": [
                                       "jdbc:mysql://127.0.0.1:3306/test"
                                   ]
                               }
                           ]
                       }
                   },
                   "writer": {
                       "name": "odpswriter",
                       "parameter": {
                           "accessId": "****",
                           "accessKey": "****",
                           "column": ["id","age","name"],
                           "odpsServer": "http://service.odps.aliyun.com/api",
                           "partition": "pt=$date",
                           "project": "datax_opensource",
                           "table": "datax_opensource_test",
                           "truncate": true
                       }
                   }
               }
           ],
           "setting": {
               "speed": {
                   "channel": 1
               }
           }
       }
   }

运行时,会自动替换为: "partition": "pt=20160612"