1.安裝datax
2.安裝python并配置環(huán)境變量
3.把mysql2odps.json文件放在datax安裝目錄的job文件夾下
4.運(yùn)行Test.java測(cè)試
mysql2odps.json文件:
{ "job": { "content": [ { "reader": { "name": "mysqlreader", "parameter": { "username": "$username", "password": "$password", "where": "optime>='$startDate $startTime' and optime<'$endDate $endTime'", "column": ["id","xm"], "connection": [ { "table": [ "test" ], "jdbcUrl": [ "$jdbcUrl" ] } ] } }, "writer": { "name": "odpswriter", "parameter": { "accessId": "****************", "accessKey": "******************************", "column": ["id","xm"], "odpsServer": "http://service.odps.xxx.com/api", "partition": "bt=$bt,region=$region", "project": "dst_project_name", "table": "test" } } } ], "setting": { "speed": { "channel": 10 } } } }
測(cè)試程序(我的datax安裝路徑為F盤(pán)根目錄):
import java.io.BufferedReader; import java.io.InputStreamReader; public class Test { public static void main(String[] args) { try { System.out.println("start"); String windowcmd = "cmd /c python F:/datax/bin/datax.py -p \" -Dusername=root -Dpassword=1234 -DjdbcUrl=jdbc:mysql://192.168.1.122:3306/center -Dwhere=left(optime,10)=CURDATE() -Dbt=20171214 -Dregion=beijing \" F:/datax/job/mysql2odps.json"; System.out.println(windowcmd); Process pr = Runtime.getRuntime().exec(windowcmd); BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line; while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); pr.waitFor(); System.out.println("end"); } catch (Exception e) { e.printStackTrace(); } } }
以上這篇Java通過(guò)python命令執(zhí)行DataX任務(wù)的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
