This section covers the steps to create a Talend Parent Child job with an example. It also helps you understand how we can pass values from Talend parent job to child job using context variables. When we want to use the child job ETL in Talend parent job, we can use tRunJob.
Talend Parent Child Job Example
To demonstrate the Talend Parent Child Job, we use the below Emp Information text file.
Create a Talend Child Job
First, we created a child job and named it as the Child_Job. Next, we used the Talend tJava component to print a simple message.
The above text file has five columns, and we want to print all the column values except the Emp ID using the child job.
In general, we don’t get the values from parent job to child job. To provide the same, we need context variables. Let me add four contexts within this the child job to accommodate those text file columns.
Within the tJava components tab, we added the following Java code.
System.out.println( StringHandling.UPCASE(context.FirstName + " " + context.LastName) + " Working as a " + context.Occupation + " earning " + context.YearlyIncome + " Monthly!" );
The above code will concat first name and last name. Then the UPCASE function converts the name to uppercase.
Create a Talend Parent Job
As you can see, we created another job called Parent_Job and added the tFileInputDelimited to load text file data into Talend.
We selected the File name using the browse button and changed the Filed separator to a comma.
Please click on the Edit Schema and add the Column names and the length.
Next, we added the tFlowToIterate to iterate the rows in a text file, and then, added the tRunJob. It means for each row in the text file, the tFlowToIterate helps to iterate tRunjob and displays the print statement.
Within the tRunJob Component tab, we have selected Child_Job.
Within the Context Param, use the add button to add the child job’s context param, i.e., FirstName. If you don’t have any context variables, then we can’t pass any values from the Parent job to child job.
Next, we assigned the FirstName of the Main row to this context parameter.
Similarly, assign the values for the remaining context parameters.
Once hit the run button of this Talend Parent Child Job, you can see the result. If you see the execution flow, tRunJob has executed ten times because there are ten rows in the Employee table.