Returning a value from a child Job to the parent Job

 

Overview

You may need to return a value or rows from a child Job to the parent Job for further use. This article shows the best practice of how to pass a value with a tBufferOutput component from a child Job to the parent Job. 

Environment

This procedure was written with:

  • Talend Open Studio for Data Integration release: 5.3.0
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3

This procedure applies to versions of Talend Open Studio for Data Integration starting from v4.2.3.

Procedure

In this tutorial, 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

Create demo Jobs

  1. Create a Job and name it childJob. It should look as in the following screenshot.



  2. To create the first subjob, add a tFileInputDelimited in the design workspace, to read data from a text file and a tLogRow to print it in the console.
  3. To create the second subjob, add a tFixedFlowInput in the design workspace, to populate the total number of rows read by the tFileInputDelimited and buffer it with atBufferOutput.
  4. Configure the tFileInputDelimited as in the following screenshot.

  5. Configure the tFixedFlowInput as in the following screenshot.



  6. Configure the tBufferOutput schema as follows.



  7. Create another Job named parentJob. The Job should look as in the following screenshot.
    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.



  8. Configure the tJavaRow as follows.



  9. Type in the following code in the Code box:

 

System.out.println("The total number of rows is:"+input_row.nb_line);
Icon

The demo Jobs and the text file required in this use case are also available in the Related File section of this article.

Execute the Jobs

Execute the parentJob Job. The results are 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]

 

Summary

In this use case, you can see the importance of using a tBufferOutput component in a child Job to buffer records. The tRunJob reads the records from the buffer and transfer them to the next component.

Version history
Revision #:
1 of 1
Last update:
‎04-14-2017 05:17 PM
Updated by:
 
Labels (1)
Contributors