Passing a value from a parent Job to a child Job

Overview

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.

 

Environment

This procedure was written with:

  • Talend Open Studio for DI 5.0-r72978
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3

The following environment was used to create the suggested procedure.

  • Data Integration releases: 4.2.3, 5.0, 5.0.2, 5.1.1

 

Procedure

This example reads data from a text file in a parent Job and passes fields from each row to the child Job. The data is used in the child Job.

in.txt:

id;name;scope
1;Shong;98
2;Ross;90
3;Tom;55
4;Patrick;99
5;Pedro;90

 

Create Parent Job

Create a Job called ParentJob. The Job design is as follows. (You will configure tRunJob in the configuration step).

1_041.png

2_035.png

 

Create Child Job

Create a child Job. Call it ChildJob.

  1. Drag and drop a tJava component from the Palette to the Job editor. In the tJava component, type in the following Java code:

    String message="Hello "+context.name+", you get "+context.scope+" points in this exam!";
    System.out.println(message);
  2. Open the Contexts viewer, and define two context variables: name and scope, as follows:

    3_018.png

 

Configure Component

Return to the parent Job, configure the tRunJob component as follows:

4_017.png

 

Execute Parent Job

Execute the Job ParentJob. The following results will print to the console:

Starting job ParentJob at 11:38 12/12/2011.
[statistics] connecting to socket on port 3768
[statistics] connected
Hello Shong, you get 98 points in this exam!
Hello Ross, you get 90 points in this exam!
Hello Tom, you get 55 points in this exam!
Hello Patrick, you get 99 points in this exam!
Hello Pedro, you get 90 points in this exam!
[statistics] disconnected
Job ParentJob ended at 11:38 12/12/2011. [exit code=0]

 

Summary

The most important technical point is using the context variable, defined in the child Job, to pass a value from parent Job to child Job.

Version history
Revision #:
2 of 2
Last update:
‎06-15-2017 08:39 PM
Updated by:
 
Labels (1)
Tags (1)