iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 25
0
Big Data

30天學會Data Integration - Kettle系列 第 25

Job動態傳遞參數

延續上一篇,此篇將介紹如何動態傳遞參數給Job使用,介紹兩種方式:
1.透過Kettle GUI傳遞參數
2.透過Command Line傳遞參數

1.透過Kettle GUI傳遞參數

開啟範例檔案

開啟 \data-integration\samples\jobs\arguments\Set arguments on a transformation.kjb
http://ithelp.ithome.com.tw/upload/images/20170108/20091626rVlEpOXdIx.png

從上一篇得知此Job的Transformation Entry是執行Run transformation.ktr檔案,其中有使用到Get System Info Step來得取三個參數,名稱分別為One、Two與Three
http://ithelp.ithome.com.tw/upload/images/20170108/20091626aoY4fdCzzL.png

執行Job

在Run Options畫面,按下Arguments(legacy)按鈕
http://ithelp.ithome.com.tw/upload/images/20170108/2009162693r4FOJqSJ.png

會出現01、02與03三個參數,分別對應One、Two與Three,Value的部份我們可以自行輸入任意值,完成後按下OK按鈕,再按下Run按鈕
http://ithelp.ithome.com.tw/upload/images/20170108/20091626CKc3NcgSmq.png

查看Excel

開啟 \data-integration\samples\transformations\output\arguments-test.xls,在這邊會發現,Excel寫入的值跟我們傳入的參數值不同
http://ithelp.ithome.com.tw/upload/images/20170108/20091626e47OwomI6h.png

請清空Run transformation.ktr Entry的Argument頁籤中的預設參數,如果你今天是想使用靜態參數就可以在這邊設定,但此篇是要以動態的方式給值,所以請按Delete鍵進行預設參數的刪除
http://ithelp.ithome.com.tw/upload/images/20170108/20091626fWaoTdYXLg.png

再重新執行一次,成功接收參數並寫入Excel檔案囉!
http://ithelp.ithome.com.tw/upload/images/20170108/20091626jHzd4ODBxd.png

2.透過Command Line傳遞參數

開啟命令提示字元

http://ithelp.ithome.com.tw/upload/images/20170108/20091626enjoEZoOQj.png

切換到解壓縮kettle的目錄下,輸入以下指令

kitchen.bat /file:<directory>\<job or transformation name> arg1 arg2 arg3
D:\data-integration>kitchen.bat /file:D:\data-integration\samples\jobs\arguments
\Set arguments on a transformation.kjb 111 222 333

http://ithelp.ithome.com.tw/upload/images/20170108/20091626gquRGFSmPA.png

執行錯誤,檔案名稱不能有空白
http://ithelp.ithome.com.tw/upload/images/20170108/20091626JGTMTcbXal.png

請複製job並更名,以下是將空白改為底線:
Set arguments on a transformation.kjb → Set_arguments_on_a_transformation.kjb

D:\data-integration>kitchen.bat /file:D:\data-integration\samples\jobs\arguments
\Set_arguments_on_a_transformation.kjb 111 222 333

http://ithelp.ithome.com.tw/upload/images/20170108/20091626lnqEJQM4x6.png

http://ithelp.ithome.com.tw/upload/images/20170108/20091626vau2bifvaI.png

執行完成
http://ithelp.ithome.com.tw/upload/images/20170108/20091626CjRuAkakxx.png

開啟Excel檔案

成功接收參數並寫入Excel檔案囉!
http://ithelp.ithome.com.tw/upload/images/20170108/20091626jHzd4ODBxd.png


Transformation使用GUI的方式與Job類似,一樣是Run Options裡面設定,另外補充透過Commamd Line執行Transformation的指令:

pan.bat /file:<directory>\<transformation name> arg1 arg2 arg3

上一篇
執行Job
下一篇
Step - Email通知
系列文
30天學會Data Integration - Kettle30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言