kettle中使用java代碼模組

來源:互聯網
上載者:User

在kettle使用java代碼模組需要注意的一些事項,以防忘記。

首先需要繼承processRow方法,跟java的main方法類似,代碼從這裡開始執行,並且在裡邊讀取跟儲存變數。

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws Exception{Object[] r = getRow();if (r == null) {  setOutputDone();  return false;}    r = createOutputRow(r, data.outputRowMeta.size());    String appid = get(Fields.In, "appid").getString(r); String appkey = get(Fields.In, "appkey").getString(r);String city_code = get(Fields.In, "city_code").getString(r);String date = get(Fields.In, "date").getString(r);Map body = new HashMap();body.put("city_code", city_code);    body.put("date", date);String sign = signRequest(appid, body, appkey);    get(Fields.Out,"sign").setValue(r,sign);logBasic("sign:"+sign);    putRow(data.outputRowMeta, r);return true;}
如上,前幾行代碼不變  讀取變數使用 get(Fields.In, "appid");

儲存變數使用get(Fields.Out,"sign").setValue(r,sign);

最後不要忘記putRow(data.outputRowMeta, r);及return true;


輸入日誌可以使用logBasic("sign:"+sign);


上面import java.util.*;

需要的jar包放入kettle安裝目錄的lib目錄下

底下變數名稱跟儲存變數名稱一樣,如下圖所示


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.