One Star

How to create variables in talend.

Hi,
here is my problem...
I am getting one file from source system named with time stamp, based on the time stamp i have to pull the data from data base.
I could pull the time from File name using the Tfilelist+TIteratetoflow but struckup with how to get the data from database based on this time stamp.
What i want to do is I want to store this timestamp value in a variable and then want to use this variable in my oracle query.
EX:if i store like TIME ='2009' and then want to use SQL QUERY like select * from ABC where time = 'TIME' to filter out the records in source query itself.
Can any one help me out in this...

Thanks in advance,
Gangadhar.
4 REPLIES
One Star

Re: How to create variables in talend.

could show a picture of your flow, maybe how you get the 'T'IME' out of your file/database whatever.... i think i got an idea.....
One Star

Re: How to create variables in talend.

Here's how I would do it:
1. Use the tSetGlobalVar component to create a global variable called "varTime" (alternatively you could just create a context variable called "varTime"
2. Inside the tFileList loop mentioned above, set the value of the varTime variable using a tJava component. You'll need to parse the filename to extract the value needed. It should look something like this: globalMap.put("varTime", <<extracted string>>); If you chose to use a context variable, it would look more like this: context.varTime = <<extracted string>>;
3. Now you probably have a tOracleInput (or other database input) inside the tFileList loop. If so, then modify your query like this: select * from ABC where time = '" + ((String)globalMap.get("varTime")) + "'" (use single quotes as needed depending on the database and data types)
Hope this helps!
One Star

Re: How to create variables in talend.

Here's how I would do it:
1. Use the tSetGlobalVar component to create a global variable called "varTime" (alternatively you could just create a context variable called "varTime"
2. Inside the tFileList loop mentioned above, set the value of the varTime variable using a tJava component. You'll need to parse the filename to extract the value needed. It should look something like this: globalMap.put("varTime", <<extracted string>>); If you chose to use a context variable, it would look more like this: context.varTime = <<extracted string>>;
3. Now you probably have a tOracleInput (or other database input) inside the tFileList loop. If so, then modify your query like this: select * from ABC where time = '" + ((String)globalMap.get("varTime")) + "'" (use single quotes as needed depending on the database and data types)
Hope this helps!

You've stolen my thougt Smiley Wink
One Star

Re: How to create variables in talend.

Hi,
Thanks for the reply. Could you please eloborate on the below step.
Inside the tFileList loop mentioned above, set the value of the varTime variable using a tJava component. You'll need to parse the filename to extract the value needed. It should look something like this: globalMap.put("varTime", <<extracted string>>); If you chose to use a context variable, it would look more like this: context.varTime = <<extracted string>>;
I am new to talend and finding it difficult to understand all the components.
Ganga.