您好,登錄后才能下訂單哦!
1.安裝datax
2.安裝python并配置環境變量
3.把mysql2odps.json文件放在datax安裝目錄的job文件夾下
4.運行Test.java測試
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 } } } }
測試程序(我的datax安裝路徑為F盤根目錄):
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通過python命令執行DataX任務的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。