如何在水壶中的用户定义的Java类中获取Field值?

时间:2016-06-28 06:01:05

标签: pentaho kettle pentaho-spoon

我正在尝试从我的下方转换中获取Link步骤中的User Defined Java Class字段。 enter image description here

以下是我在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;

}

当我运行上面的代码时,这是我在用户定义的Java类步骤中得到的错误:

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步骤:

enter image description here

我哪里错了?

1 个答案:

答案 0 :(得分:5)

我想出了我失踪的地方。在User Defined Java Class,在下面的参数标签中,我需要明确定义字段名称及其别名,例如:enter image description here