My simplified job look like this:
tSetGlobalVar--->(onSubJobOK)--->tRunJob--->(onSubJobOK)--->tJava
myKey:"firstValue"
((String)globalMap.get("myKey")): "newValue"
also tried this:
"myKey": "newValue"
System.out.println(((String)globalMap.get("myKey")));
Actual output: firstValue
Expected output: newValue
Is there any other way to modify the value of a global variable in a subjob and get the updated value in the master job ?
You should be passing data to your child job by using context variables rather than the globalMap. You then pass data back up to the parent job using a tBufferOutput in the child job.
As an example, here's a very basic setup that takes an id and a date and passes it to a child job which simply prints it to the console/logs and then passes some data back up to the parent that is also just printed to the console/logs.
Parent job:
The data in the tFixedFlowInput in the parent job is as follows:
Notice how you must use a key value pair combination for the key and the value to pass it to the tContextLoad component which will then create a context variable named by the key and holding the defined value.
In the parent job we set the id
and date
context variables and then straight away print the current contexts for the job (which will include the context variables just set).
After this we then call the child job using a tRunJob component set to pass the entire context:
Alternatively you can specify which context variables you pass to the child job by unticking the Transmit whole context
option and explicitly defining which contexts to send. It is also possible to define the value of the context variables here but it typically makes more sense to generate the context variable values in the main flow of your job and pass them as a key value pair to the tContextLoad component.
Child job:
In the child job we simply print the contexts that have been sent by dumping them to a tLogRow with a tContextDump component and then after that we use another tFixedFlowInput to hard code some data in this case:
Which we then pass to a tBufferOutput component which allows us to read the data back in the parent job.
Going back to the parent job we then link a tLogRow to the tRunJob with a main link and provide the schema that is in the child job's tBufferOutput. This then prints the data from the child job.
The example job's output is then:
.----+----------.
|Parent Contexts|
|=---+---------=|
|key |value |
|=---+---------=|
|date|2014-10-30|
|id |12345 |
'----+----------'
.----+----------.
|Child Contexts |
|=---+---------=|
|key |value |
|=---+---------=|
|date|2014-10-30|
|id |12345 |
'----+----------'
.-----+----------.
|Child Data to be Passed to Parent|
|=----+---------=|
|id |date |
|=----+---------=|
|12346|2014-10-31|
'-----+----------'
.-----+----------.
|Output from Child1|
|=----+---------=|
|id |date |
|=----+---------=|
|12346|2014-10-31|
'-----+----------'
The globalMap stores data in the job itself and is not shared at all with parent or child jobs so cannot be used for this purpose.