Adding fields

Adding new fields to the dataset is really simple. This is how you do it:

  1. In the code, you define the field as an internal variable and calculate its value.
  2. Then you have to update the output row. Supposing that the name for the new field is my_new_field and the name of the internal variable is my_var, you update the output row as follows:
get(Fields.Out, "my_new_field").setValue(outputRow, my_var); 
  1. Finally, you have to add the field to the lower grid. You just add a new line of each new field. You have to provide at least the Fieldname and Type.
To know exactly which type to put in there, refer to the Data types equivalence section of this chapter.

In our example, we want to add a field to the length of the word field. ...

Get Learning Pentaho Data Integration 8 CE - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.