Tuesday, June 18, 2013

A Quick Report with Talend Open Studio


If you don't have Jasper around, you can create a report or an extract with extra headers or text using the a tForeach and a tIterateToFlow.


There's a Jasper report component available, but if you don't have Jasper installed, you can create a report using a basic input/tMap/output subjob preceded by a header subjob or followed by a footer subjob.  The header and footer subjobs can use a set of values in a tForeach to produce a line of text for insertion into the report.

Talend Open Studio - A Report
 tForeach uses a set of values defined in the component to write out lines to a text file, the tFileOutputDelimited_2.  A tIterateToFlow component is needed to "convert" the tForeach iteration to a data flow.  The tIterateToFlow component has a single field that it outputs which is the value from the tForeach.

The key in this map is to have each subjob writing to the same output report file in sequence.  The header subject uses tFileOutputDelimited_1 and a simple one-field schema to write to a file called 'report.csv'.  The main subjob has "Append" checked and writes to the same report.csv file.

Set the text values in the tForeach component.

Talend Open Studio - tForeach Config

Create a single-field schema for a "File delimited".  In the tIterateToFlow component, map the value of a global variable to the single field.  The global variable is the current value from the tForeach component.
Talend Open Studio - tIterateToFlow Config
 The tFileOutputDelimited_2 component uses a single-field schema to receive the global variable.

This is a screenshot of the schema for tFileOutputDelimited_2.  It was created by pressing the "Edit schema" button on the tFileOutputDelimited_2 component tab.

Talend Open Studio - A One-Field Schema for Report Headers

The remainder of the job uses a tMap to write an Excel file to tFileOutputDelimited_1.  tFileOutputDelimited_1 does not use the single-field schema, though it points to the same actual file as tFileOutputDelimited_1.  It uses one that resembles the Excel file.   Remember to specify Append for tFileOutputDelimited_1 or the header will be overwritten.

This is the schema for tFileOutputDelimited_1.  It was created by linking up a previously-created metadata item using the "Repository" setting.

Talend Open Studio - Schema for Report Data

The tForeach component lets you define a list of items which can then be written out to a text file.  The tForeach can be used before and after to produce a header or a footer.  For more advanced reporting, especially if writing HTML, use a reporting engine like Jasper.

No comments: