Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Tuesday, May 10, 2011

To Iterate or Flow in Talend Open Studio

When working with RDBMS or Web Services components, Talend Open Studio jobs use Flows.  For systems programming -- file operations, etc. -- jobs use Iterators.  Use a Flow where possible, but keep things as Iterate if most of the components are Iterate connection-based.

In Talend Open Studio, looping or repeating actions are formed using either Flows or Iterators.  To bridge the two, there are adapter components: tIterateToFlow, tFlowToIterate.

Take the following job as an example

Two Forms of Repeating Actions in TOS

Two tFileLists are used to drive the processing (a System.out.println).  The first tFileList uses the Iterate connector fed into a tJava.  For each file found in the tFileList, the tJava is invoked.  No data is sent to the tJava.  The tJava accesses a global variable available after each tFileList iteration.

tJava Code Iterate Connector

To convert the list of files into a Flow where each file is a row, use the tIterateToFlow adapter.  This requires defining a schema that will be filled in the Mapping section of the tIterateToFlow adapter.

Single Column Schema of a tIterateToFlow
Because the tFileList is converted to a Flow, accessing global variables isn't needed.  The data is available using the standard 'row' syntax like this.  This means that Flow-based components like tFilterRow can be used most effectively (recording the number of rows processed, etc.).

Flow-based Code Displaying tFileList
Depending on your Job, you have flexibility in selecting an Iterate or Flow.  There are adapters that convert from one to the other.  One rule of thumb in making your selection is if your job would benefit from having a structured schema associated with you iteration-based components.  In this post, a single-field schema is used to transport the values from the tFileList.  This could be expanded to additional values.

1 comment:

  1. I have an iterate section in my job, but cannot connect it back to flow to write all the results into a database. (as iterate would write one by one). My last task in the iterate chain is a replace, but I cannot connect it back to titeratetoFlow. Why? What shall I use?