[resolved] Iterate differing variables to component

Highlighted
One Star

[resolved] Iterate differing variables to component

Hi all,
Simple question without much introduction needed for it - Let's say I have 48 different variables (taken from a list of ID numbers) and I need an input component to look up a URL based on each individual ID number - Hence I need each ID as a variable to automate the job (the ID's change daily).
So inside my input I have ' "URL.LINK&" +globalMap.get("ID_value_"+globalMap.get("V")) ' as the link. But how do I iterate V = 1,2,3 etc into the component?
I have a clever java loop which saves each ID as ID_value_N for however many N integer values needed, but I cannot think of a way of importing that into a single file-name path.
Any help is appreciated.
Regards,
V Pem.

Accepted Solutions
Community Manager

Re: [resolved] Iterate differing variables to component

Hi 
If you want to iterate number from 1 to Y (it is 48 for example) and send it as a parameter to the next processing, you can use tLoop component to a loop. For example:
your other component--main(row1)--tJavaFlex (Here I use tJavaFlex to replace tJavaRow)
    |
onsubjobok
    |
tLoop--iterate--tJava--oncomponentok--your other processing.
on tJavaFlex:
in the beginning part
Integer Y=0;

in the main part:
Y = (Integer)globalMap.get("N");
globalMap.put("film_edi_"+Y, row1.film_edi);
globalMap.put("N", new Integer(Y.intValue() + 1));

in the end part, store the value of Y to a context variable called Y for use later.
on tLoop, set Condition field with a context variable called condition.

on tJava:
int current_iterate=((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"));
if(current_iterate<context.Y){
context.condition=true;
}else{
context.condition=false;
}

//the current value of Y can be accessed with this expression in your other processing:
((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))
I am not sure I understand your request completely, but hope that it might give you some tips to use tLoop to do a loop.
BR
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post


All Replies
Community Manager

Re: [resolved] Iterate differing variables to component

where is the value of V stored?
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Iterate differing variables to component

Not entirely sure..? In the workings of talends variables. Here is the code from my tJavaRow that produces the entire variable:
Integer Y = (Integer)globalMap.get("N");
globalMap.put("film_edi_"+Y, input_row.film_edi);
globalMap.put("N", new Integer(Y.intValue() + 1));

Apologies, it is Y, not V - Regardless, it doesn't really matter. How would I iterate the differing value into the input component? Since, at the end of the Java component, Y is set to 48. How would I iterate it through all the integer values going INTO the input? Essentially, how do I loop the input to run mutliple times?
Community Manager

Re: [resolved] Iterate differing variables to component

Hi 
If you want to iterate number from 1 to Y (it is 48 for example) and send it as a parameter to the next processing, you can use tLoop component to a loop. For example:
your other component--main(row1)--tJavaFlex (Here I use tJavaFlex to replace tJavaRow)
    |
onsubjobok
    |
tLoop--iterate--tJava--oncomponentok--your other processing.
on tJavaFlex:
in the beginning part
Integer Y=0;

in the main part:
Y = (Integer)globalMap.get("N");
globalMap.put("film_edi_"+Y, row1.film_edi);
globalMap.put("N", new Integer(Y.intValue() + 1));

in the end part, store the value of Y to a context variable called Y for use later.
on tLoop, set Condition field with a context variable called condition.

on tJava:
int current_iterate=((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"));
if(current_iterate<context.Y){
context.condition=true;
}else{
context.condition=false;
}

//the current value of Y can be accessed with this expression in your other processing:
((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION"))
I am not sure I understand your request completely, but hope that it might give you some tips to use tLoop to do a loop.
BR
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

One Star

Re: [resolved] Iterate differing variables to component

Waaahooooo!! Finally got it! Thank you Shong. tLoop was EXACTLY what I needed. Such a simple answer and it took me so long to find it haha.
I probably could have done it your way, but I changed it slightly - For the purpose of others I will detail below, thanks again.
So after my initial Java loop which sets the variables ID_value_N for all integer values N required, I did onSubjobOkay --> tLoop --Iterate--> tJava --OnComponentOkay--> Other part of my job.
Inside the tLoop I did:
Loop Type: For
From 1
To (Integer)globalMap.get("N") -1
Step 1
This makes sense if you look at the code for my tJavaFlow which sets the initial value Y from the integer N as follows:
Integer Y = (Integer)globalMap.get("N");
globalMap.put("N", new Integer(Y.intValue() + 1));
This means that after it sets the final variable ID_value_48, it sets the value N as 49 before finishing the component, hence the -1 in the tLoop.

As for the tJava, I do the following:
Integer W = (Integer)globalMap.get("V");
globalMap.put("V", new Integer(W.intValue() + 1));
Similar loop as to the one above, simply giving me a new value to play with so I needn't interfer with the original variable N (for safety reasons). Then I call upon the variable ' +globalMap.get("ID_value_"+globalMap.get("V")) ' in my input component after the tJava which iterates through the values as a result of the tLoop... Awesome! Smiley Happy
Note: If anyone does a similar thing, make sure to do 'Append' in the output, as I initially over-wrote my file several times before realising what I was doing haha.
Regards,
V Pem.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog