Passing a value from the parent Job to the child Job is a common real world requirement. I am going to describe different ways of passing values from parent job to child job using following different ways.
Passing context to child job.
Passing globalMap to child and get the result back in parent.
Get the result from child job to Parent.
Use Case 1: Pass a context variable and filter the data in child job.
Step 2: Open Parent job and do the following modifications.
Add tSetGlobalVar component and configured as follows.
Parent Job design & tSetGlobalVar settings.
Use “OnComponentOk” trigger to connect with tRunJob.
Add tJava after tRunJob and connect using “OnSubJobOk” trigger with tRunJob component, add the following code in tJava.
System.out.println("Value From Child Job: "+globalMap.get("Id"));
Step 3: Save the parent job and execute it will show you following output.
Use Case 3: Get the result from child job to Parent.
previous use case we have seen, how to pass value to the child and get the result using globalMap variables, but this is not convenient way in terms of maintaining and manipulating keys, java code.
But there is sophisticated way to perform this task by using tBufferOutput component & tRunJob schema option.
Do the following changes in both the job.
Step 1: Open and modify child job as follows.
Remove tJava & tJavaRow component and add tBufferOutput at tJavaRow’s place.
Connect tBufferOutput with tMap using “filterData” output link and click on synch button.
Step 2: Do the following changes in Parent job.
Remove tSetGlobalVar & tJava component and add tLogRow at tJavas place.
In tRunJob setting do the following changes.
Click on “Copy child Job Schema”, it will show you schema copied from child job.
Add tlogRow and connect with tRunJob using Main Link.
Step 3: Save the Parent Job and execute it will display below output on console.
We have seen various ways of passing to and receiving values from child job. every way has it`s pros and cons but if you ask me I will prefer the way which is best suitable for my case.
I am Software consultant with approx 7 years of experience mainly in Business Intelligence and data warehousing assignments using Talend.
Writing is not my passion but i am doing it to help others. if you have any special case where you want me to demonstrate then please post me.