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.

    childJob.png

    Note: The demo Jobs and the text file are also available in the attached Zip file.

     

  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 a tBufferOutput.
  4. Configure the tFileInputDelimited as in the following screenshot.

    tFileInputDelimited_settings.png

     

  5. Configure the tFixedFlowInput as in the following screenshot.

    tFixedFlowInput_settings.png

     

  6. Configure the tBufferOutput schema as follows.

    tBufferOutput_settings.png

     

  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.

    parent_job.png

     

  8. Configure the tJavaRow as follows.

    tjavarow.png

     

  9. Type the following code into the Code box:

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

 

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 transfers them to the next component.

Version history
Revision #:
2 of 2
Last update:
‎06-29-2017 10:09 AM
Updated by:
 
Labels (1)
Tags (1)