Tuesday, February 9, 2021

User defined Java Class getRow null

 I have been working with Pentaho Kettle, and I needed to add some scripts, I decided to use Java since you can import some extra libraries, which is not allowed on Javascript component (or I haven't found how). 


I read the documentation and I implemented the processRows method, while testing I realized that getRow method was returning 'null' every time, at the beginning I thought it was related to the input type so I tried a couple, json, csv, excel, etc, and I always had the same result.


What was the solution? I was missing `putRow(...)` line, I am not sure what internally does but after adding it then getRow() started sending objects instead of null. I mean it makes kind of sense since if you miss putRow then whatever you do inside this component will not propagate further, I just wish it was documented somewhere.


So your code should look like this:



public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException

{

// you need this

Object[] r = getRow();

// this

r = createOutputRow(r, data.outputRowMeta.size());

// and this to send the row on to the next step.

putRow(data.outputRowMeta, r);



return true;

}