You may need to return a value or rows from a child Job to the parent Job for certain use. Let us see the best practice of how to pass a value with a tBufferOutput component from a child Job to the parent Job.
If you would like to Enrich your career with a Talend certified professional, then visit Mindmajix - A Global online training platform: “Talend Certification Course”. This course will help you to achieve excellence in this domain.
Here, you will create two Jobs: a parent Job and a child Job. The child Job will read data from a text file, populate the total number of rows and pass the rows to the parent Job.
The input file, named in.txt, is as follows:
id;name 1;Shong 2;Elise 3;Sabrina
This parentJob is created to call the childJob Job with a tRunJob component, get the value buffered by tBufferOutput in the child Job and pass it to a tJavaRow.
System.out.println("The total number of rows is:"+input_row.nb_line);
Execute the parentJob .The results is printed in the console:
Starting job parentJob at 14:37 16/06/2013. [statistics] connecting to socket on port 3801 [statistics] connected 1|Shong 2|Elise 3|Sabrina The total number of rows is:3 [statistics] disconnected Job parentJob ended at 14:37 16/06/2013. [exit code=0]
In this recipe, we will see how RETURN CODES can be set in a child job and used in a parent, without having to kill the child process.
Open the job jo_cook_ch11_0060_childReturnCodesNoDie. This job is the end state of the previous recipe.
How to do it…
The first thing we need to do is add the return code value to a buffer for the parent job to pick up.
Buffering the return code
How it works…
The tBufferOut component is used to transmit data from a child job to a parent, and we can easily access the schema of the child job (as set in the tBufferOut component) using the Copy Child Job Schema option in the tRunJob component.
When the parent picks up the code, it stores it in a globalMap variable for use by the If conditions.
Passing parameters to a child job
Talend provides us a very good way of inter-component communication using parameters. We can easily pass the context parameters from one job to another. This feature is very handy as we can create all the parameters in the main job and as per requirement, pass the values of parameters to the sub jobs.
First, create a child job :
EMP_ID;EMP_NAME;EMP_SALARY 101;Mark THomas;20,000 102;William Crow;53,000 103;Ramanujan K.;89,000 104;Stacy Wind;24,000
5. Open the settings of the child subjob and pass the values of the context variables defined in child job. Take the values of the fields from row2 link and pass it to context variables.
6. Main job is complete. It’s time to execute it.
Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.