如何在水壶中获取用户定义的Java Class中的字段值?
How to get Field value in User Defined Java Class in kettle?
我正在尝试从下面的转换中获取 User Defined Java Class
步骤中的 Link
字段。
这是我在 User Defined Java Class
中编写的代码:
private String link;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
Object[] r=getRow();
if (r == null) {
setOutputDone();
return false;
}
if (first) {
link = getParameter("Link");
first = false;
}
String linkField = get(Fields.In, link).getString(r);
logBasic("link:" + link);
return true;
}
当我运行上面的代码时,这是我在用户定义JavaClass步骤中得到的错误:
2016/06/28 11:26:57 - User Defined Java Class.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : Unexpected error
2016/06/28 11:26:57 - User Defined Java Class.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : org.pentaho.di.core.exception.KettleStepException:
2016/06/28 11:26:57 - User Defined Java Class.0 - Unable to find In field helper for field name 'null'
2016/06/28 11:26:57 - User Defined Java Class.0 -
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.steps.userdefinedjavaclass.TransformClassBase.get(TransformClassBase.java:628)
2016/06/28 11:26:57 - User Defined Java Class.0 - at Processor.processRow(Processor.java:15)
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClass.processRow(UserDefinedJavaClass.java:1018)
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2016/06/28 11:26:57 - User Defined Java Class.0 - at java.lang.Thread.run(Thread.java:745)
2016/06/28 11:26:57 - User Defined Java Class.0 - Finished processing (I=0, O=0, R=1, W=0, U=0, E=1)
为了确认字段,这里是预览数据的快照,直到 Filter rows
步骤:
我哪里错了?
我想出了我失踪的地方。在User Defined Java Class
下面的Parameters选项卡中,我需要明确定义字段名和它的别名,比如:
我正在尝试从下面的转换中获取 User Defined Java Class
步骤中的 Link
字段。
这是我在 User Defined Java Class
中编写的代码:
private String link;
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
Object[] r=getRow();
if (r == null) {
setOutputDone();
return false;
}
if (first) {
link = getParameter("Link");
first = false;
}
String linkField = get(Fields.In, link).getString(r);
logBasic("link:" + link);
return true;
}
当我运行上面的代码时,这是我在用户定义JavaClass步骤中得到的错误:
2016/06/28 11:26:57 - User Defined Java Class.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : Unexpected error
2016/06/28 11:26:57 - User Defined Java Class.0 - ERROR (version 5.4.0.1-130, build 1 from 2015-06-14_12-34-55 by buildguy) : org.pentaho.di.core.exception.KettleStepException:
2016/06/28 11:26:57 - User Defined Java Class.0 - Unable to find In field helper for field name 'null'
2016/06/28 11:26:57 - User Defined Java Class.0 -
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.steps.userdefinedjavaclass.TransformClassBase.get(TransformClassBase.java:628)
2016/06/28 11:26:57 - User Defined Java Class.0 - at Processor.processRow(Processor.java:15)
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.steps.userdefinedjavaclass.UserDefinedJavaClass.processRow(UserDefinedJavaClass.java:1018)
2016/06/28 11:26:57 - User Defined Java Class.0 - at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2016/06/28 11:26:57 - User Defined Java Class.0 - at java.lang.Thread.run(Thread.java:745)
2016/06/28 11:26:57 - User Defined Java Class.0 - Finished processing (I=0, O=0, R=1, W=0, U=0, E=1)
为了确认字段,这里是预览数据的快照,直到 Filter rows
步骤:
我哪里错了?
我想出了我失踪的地方。在User Defined Java Class
下面的Parameters选项卡中,我需要明确定义字段名和它的别名,比如: