Skip a component based on condition in Talend

Rakesh Shrama picture Rakesh Shrama · Jul 1, 2014 · Viewed 15.6k times · Source

I have a scenario where I would like to skip a component to execute based on the condition and run its consecutive components in Talend.

Is it at all possible?

Answer

ydaetskcoR picture ydaetskcoR · Jul 3, 2014

You have two options available to you for conditionally executing parts of your job.

Where the component that follows your conditional check can be a starting component (if you drop it to the canvas then it should have a green background) then you can use the Run if connector to link it to the previous part of your job like so:

Run If Job Setup

In this example we simply call another tJava component conditionally but this could be any component that is startable.

Where the first tJava component (Set condition boolean) is configured with the following code:

Boolean condition = false;
globalMap.put("condition",condition);

And the two Run if connectors are set as ((Boolean)globalMap.get("condition")) == true and ((Boolean)globalMap.get("condition")) == false respectively.

A better option may be to use the filtering in a tMap or tFilterRow component and this also allows you to link to components that aren't starting components. To do this you would set your job up as below:

tMap Conditional Job Setup

In this job I have hard coded some tabular data in a tFixedFlowInput component:

tMap Conditional Job Data

We then use a tMap to filter the flows of data to any following components:

tMap Conditional Job Data tMap configuration

In which we test the value of the boolean condition column of our data. As an illustration I have also applied some simple, conditional transformation to the data where "true" rows have 1000 added to their value and "false" rows have 100 subtracted from their value.

From here you can then carry on the flow of your job as normal, in this case we link to a tSystem component to execute system commands as per your comment.