How to get Field value in User Defined Java Class in kettle?

psr picture psr · Jun 28, 2016 · Viewed 7.9k times · Source

I am trying to get the Link field in the User Defined Java Class step from my below transformation. enter image description here

Here is the code which I have written in 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;

}

When I run the above code, here is the error that I get at the User Defined Java Class Step:

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)

To confirm the fields, here is the snapshot of Preview Data till the Filter rows step:

enter image description here

Where am I going wrong?

Answer

psr picture psr · Jun 28, 2016

I figured out where I was missing. In the User Defined Java Class, in the Parameters tab below, I need to explicitly define the field name and it's alias, such as: enter image description here