Six Stars

Loop through input file to populate context variable to be used in job

Talend 5.4
Linux 6.2
I want to read a text file that contains one value per row, use that value to populate a context variable (or a variable) and then go to a sub job that uses the variable, then repeat through file (and the process) until the end of file.
How to do?
Thank you all.
4 REPLIES
Moderator

Re: Loop through input file to populate context variable to be used in job

Hi,
From your description, it seems that you are looking for tContextLoad or Implicit tContextLoad.
Could you please take a look at component:TalendHelpCenter:tContextLoad
and a forum about How to use Implicit tContextLoad in use case https://www.talendforge.org/forum/viewtopic.php?id=35478 to see if it is satisfying your needs?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Six Stars

Re: Loop through input file to populate context variable to be used in job

In the link you provided, if you look at some of the responses, Shong comes close to what I am looking for when he states the following:
You can use tFlowToIterate to iterate all rowss one by one, for example:
tFileInputDelimited--main(row1)-->tFlowToIterate--iterate--tRSSInput--main--tLogRow
on tRSSInput, set the RSS URL field as: row1.url

However, what I need in place of the tRSSInput would be a tContextLoad.  And then once the context is loaded I need to call another subjob to use that context.  Then I need to repeat this step for each row in the tFileInputDelimited.  That input file, by the way, would have the following structure (i.e. same context key, different values):
name=John
name=Carol
name=Joan
...
Please advise and if you have a snapshot of the flow that would help tremendously.
One Star

Re: Loop through input file to populate context variable to be used in job

In the link you provided, if you look at some of the responses, Shong comes close to what I am looking for when he states the following:
You can use tFlowToIterate to iterate all rowss one by one, for example:
tFileInputDelimited--main(row1)-->tFlowToIterate--iterate--tRSSInput--main--tLogRow
on tRSSInput, set the RSS URL field as: row1.url

However, what I need in place of the tRSSInput would be a tContextLoad.  And then once the context is loaded I need to call another subjob to use that context.  Then I need to repeat this step for each row in the tFileInputDelimited.  That input file, by the way, would have the following structure (i.e. same context key, different values):
name=John
name=Carol
name=Joan
...
Please advise and if you have a snapshot of the flow that would help tremendously.

I would replace tRSSInput by tJavarow and tLogRow by tRunJob (your child job)
Six Stars

Re: Loop through input file to populate context variable to be used in job

I figured this out by just using tJavaFlex in place of tRSSInput and adding some Java (see below)....

context.name = ((String)globalMap.get("row1.name"));
row2.name = context.name;


thanks for all your help.