前言
如果您觉得有用的话,记得给博主点个赞,评论,收藏一键三连啊,写作不易啊^ _ ^。
而且听说点赞的人每天的运气都不会太差,实在白嫖的话,那欢迎常来啊!!!
Kettle java脚本组件的使用说明(简单使用、升级使用)
01 简单使用
获取java脚本组件
打开你刚刚移动过来的java脚本
几个地方要记住
main方法,
点击后可以看到出来一大坨代码:
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
if (first) {
first = false;
/* TODO: Your code here. (Using info fields)
FieldHelper infoField = get(Fields.Info, “info_field_name”);
RowSet infoStream = findInfoRowSet(“info_stream_tag”);
Object[] infoRow = null;
int infoRowCount = 0;
// Read all rows from info step before calling getRow() method, which returns first row from any
// input rowset. As rowMeta for info and input steps varies getRow() can lead to errors.
while((infoRow = getRowFrom(infoStream)) != null){
// do something with info data
infoRowCount++;
}
/
}
Object[] r = getRow();
if (r == null) {
setOutputDone();
return false;
}
// It is always safest to call createOutputRow() to ensure that your output row’s Object[] is large
// enough to handle any new fields you are creating in this step.
r = createOutputRow(r, data.outputRowMeta.size());
/ TODO: Your code here. (See Sample)
// Get the value from an input field
String foobar = get(Fields.In, “a_fieldname”).getString®;
foobar += “bar”;
// Set a value in a new output field
get(Fields.Out, “output_fieldname”).setValue(r, foobar);
*/
// Send the row on to the next step.
putRow(data.outputRowMeta, r);
return true;
}
几个关键的地方
输入流中取出你上级传入的字段内容用
String foobar = get(Fields.In, “a_fieldname”).getString®;
a_fieldname是你上级输入的字段名
如果想改变你上级输入的内容的话,用这个
get(Fields.Out, “output_fieldname”).setValue(r, fooba