Talend ETL Tutorial : How To Loop Using Talend Component

Praveen Singh         No comments





There are multiple scenarios where looping is required. The looping concept is present in all programming language and you must have used it somewhere. The question is how to use it in Talend? Fortunately, Talend provides a lof of looping components for this purpose. And, if any of the components is not able to fulfill your requirement then you can also write your custom code.

Looping Components Available In Talend

tLoop

This component is same as your programming language loop. You can define the Start and End of the loop with the incremented step. It operates on the task execution. It allows you to execute a task or job automatically based on a loop.tLoop is to be used as a start component and can only be used with an iterate connection to the next component.You can loop through either using FOR or WHILE loop.

Get more details here : tLoop Component Details

For Loop Settings :



While Loop Settings :



tLoop In Action 

In simple terms, we can use this to iterate a job n number of times. There could be a requirement to execute a specific job multiple times, so instead of calling it multiple times , we can just pass it in the tLoop. So, basically, it works on Parent and Child relationship. The job where the tLoop component is being used, will work as the Parent component. 

For the demo, I am going to use one of  the existing jobs ( HowToReadMultipleFiles ). This job will work as a child because it will be called by a tLoop job multiple times. 

Child Job 


Parent Job



Final Job Execution :

tLoop Component :


tRunJob Component :



tSleep Component :




We are going to call our child Job 3 times as per our Loop settings. And in one run , this child job prints 4 lines at the console so it means at the end of our Parent job run, we will see 12 lines of output on the console.



tForEach 

tForeach creates a loop on a list for an iterate link. tForeach allows you to to create a loop on a list for an iterate link. tForeach is an input component and requires an Iterate link to connect it to another component. You can insert any value in the double quotes to be iterated upon.



Get more details here : tForEach Component Details

tForEach In Action

For the demo purpose, I have created a simple Job here. We are going to iterate above defined value in the tForEach settings. Will just display the records on the console using tJava component. tJava component is required when we have to write our custom code. As you could have guessed it already, this should be written in Java.

tJava Component 

This component has an only window : Code. You can write your desired Java code here and this component will execute it.


tForEach Job Execution :


tFileList

This component is important when we have to loop through the directories and files. tFileList retrieves a set of files or folders based on a filemask pattern and iterates on each unity. I have covered this component in detail in one of my previous post with the job execution.

Please find the detail here : Job execution with tFileList component



Published by Praveen Singh

A blogger by passion.You can find me tucked in my bed and blogging on weekends when not roaming around. Besides blogging, I love music and you can find my songs on my fb page:PraveenUnplugged
.
Follow on Youtube : Videos On Latest Happenings |ThingsToKnow
.
Follow us Talend In Action

0 responses:

© 2015 Techie's House. Designed by Bloggertheme9