Returning a value from a child Job to the parent Job

author
Shicong Hong
EnrichVersion
6.4
6.3
6.2
6.1
6.0
EnrichProdName
Talend Open Studio for Big Data
Talend Data Fabric
Talend Real-Time Big Data Platform
Talend Data Services Platform
Talend Open Studio for ESB
Talend Big Data Platform
Talend Big Data
Talend ESB
Talend Open Studio for MDM
Talend MDM Platform
Talend Open Studio for Data Integration
Talend Data Integration
Talend Data Management Platform
task
Data Governance > Third-party systems > Buffer components
Data Quality and Preparation > Third-party systems > Buffer components
Design and Development > Third-party systems > Buffer components
EnrichPlatform
Talend Studio

Returning a value from a child Job to the parent Job

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 from a child Job to the parent Job using the tBufferOutput component.

Creating the child Job

In this tutorial, you will create two Jobs: a parent Job and a child Job. The child Job reads data from a text file, populates the total number of rows and passes the rows to the parent Job.

The input file, named in.txt, is as follows:

id;name
1;Shong
2;Elise
3;Sabrina

This Job uses the following components:

  • a tFileInputDelimited component to read data from a text file and a tLogRow to print it on the console to create the first subjob,
  • a tFixedFlowInput component to populate the total number of rows read by the tFileInputDelimited and buffer it with a tBufferOutput.

Procedure

  1. Create a Job and name it childJob.
  2. Add a tFileInputDelimited component and a tLogRow component on the workspace and link them with a Row > main connection.
  3. Add a tFixedFlowInput component and a tBufferOutput on the workspace and link them with a Row > main connection. Link the first subjob to the second with a Trigger > On Subjob Ok connection.
  4. Double-click the tFileInputDelimited component to open its Basic settings view and fill the File name/Stream with the .txt file path and the Header field with 1.
  5. Click the Edit schema button and create a double column schema as below:
  6. Double-click the tFixedFlowInput and create a one column schema named nb_line of Integer type. In the Values table, add the value ((Integer)globalMap.get("tFileInputDelimited_1_NB_LINE")).
  7. Double-click the tBufferOutput component and configure its schema as follows:

Creating the parent job

This Job uses the following components:

  • a tRunJob component to call the childjob and get the value buffered by the tBufferOutput component in the child Job and pass it to a tJavaRow component.

Procedure

  1. Create a Job and name it parentJob.
  2. Add a tRunJob and a tJavaRow components on the workspace and link them with a Row > main connection.
  3. Double-click the tRunJob component to open its Basic settings view. Select childJob in the Job field and check if the schema of the tRunjob corresponds with the schema of tBufferoutput called in the Job.
  4. Double-click the tJavaRow component and add the following code in the Code field:
    System.out.println("The total number of rows is:"+input_row.nb_line);
  5. Double-click the tBufferOutput component and configure its schema as follows:
  6. Execute the parentJob Job. The results are printed on the console:
    Tip: The importance of using a tBufferOutput component in a child Job is to buffer records. The tRunJob reads the records from the buffer and transfers them to the next component.