Passing a value from a parent Job to a child Job

author
Shicong Hong
EnrichVersion
6.5
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
Design and Development > Designing Jobs
EnrichPlatform
Talend Studio

Passing a value from a parent Job to a child Job

Passing a value from the parent Job to the child Job is a common real world requirement. This article serves as a best practice guide.

In this example, you read data from a text file in a parent Job and pass fields from each row to the child Job. The data is used in the child Job.

Create and configure the parent Job

Before you begin

  • You have created a text file, in this example in.text.
    id;name;scope
    1;Shong;98
    2;Ross;90
    3;Tom;55
    4;Patrick;99
    5;Pedro;90

Procedure

  1. Create a Standard Job called ParentJob and configure it as follows.
  2. Double-click the tFileInputDelimited to open its Basic settings view and then configure its parameters.
    • Click the [...] button next to the File Name/Stream field and browse to the source file, in this example in.txt.
    • Set Header to 1.
    • Click the Edit schema button and add three columns to the schema, id as Integer, name as String and scope as Integer.
  3. In the Basic settings of the tFlowToIterate, make sure that the Use the default (key,value) in global variables. box is checked.
  4. Press Ctrl+S to save your Job.

Create and configure the child Job

Procedure

  1. Create a Standard Job called ChildJob.
  2. Open the Contexts tab to define two context variables, name and scope.

    These variables are used to pass a value from the parent Job to the child Job.

  3. Add a tJava component from the Palette to the Job editor and double-click the component to open its Basic settings.
  4. In the Code area, type in the following Java code.
    String message="Hello "+context.name+", you get "+context.scope+" points in this exam!";
    System.out.println(message);
  5. Press Ctrl+S to save your Job.

Configure the tRunJob component

Before you begin

  • You have defined the two context variables in the child Job.

Procedure

  1. In the parent Job, open the Basic settings view of the tRunJob component to configure its parameters.
  2. In the Job field, select the child Job, in this example ChildJob.
  3. In the Context Param field, click the [+] button to add the two parameters defined in the Context tab of the child Job, in this example name and scope.
  4. Define the value for each parameter, (String)globalMap.get("row1.name") for name and (Integer)globalMap.get("row1.scope") for scope.
  5. Press Ctrl+S to save your changes.
  6. Press F6 to execute the parent Job, in this example ParentJob.

Results

The following results print to the console.