One Star

[resolved] creating and using Arraylists in Talend

I am reading a series of values from an XML iteratively,
tFlowToIterate->tFixedFlowInput.
I want to store these values in an Arraylist say, myArrlist, as myArrList, myArrList,myArrList and so on.
How may I define myArrList and a index value (initialised to 0) globally in Talend so that i can keep incrementing the index and keep appending values to my Arraylist?
Thanks.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] creating and using Arraylists in Talend

Thanks a lot Sabrina. That post really helped!!
The problem was also that I was using tFlowToIterate->tFixedFlowInput to iterate my XML. So it was creating the arraylist for each iteration even in the main section of tjavaflex!
12 REPLIES
Moderator

Re: [resolved] creating and using Arraylists in Talend

Hi,
You can use component tjavaFlex to store these values in an Arraylist. In addition, elaborating your case with an example with input and expected output values will help us to give you a precise answer.
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.
One Star

Re: [resolved] creating and using Arraylists in Talend

Hi Sabrina,
I tried using tjavarow. Problem is, each time the next element is processed, the previous element in the arraylist simply gets overridden.
Let me elaborate on that. Suppose I have an XML in this format,
<root>
<row>
<name>one</name>
<id>1</id>
</row>
<row>
<name>two</name>
<id>2</id>
</row>
</root>
I am reading this XML using tfileinputXML->tFlowToIterate->tFixedFlowInput->tjavarow with the schema of both name and id.
I created an 2 Arraylists, myarr1(for name) and myarr2(for id) in my tjavarow.

So when i perform a myarr1.add(input_row.name) and myarr2.add(input_row.id), the first iteration stores the values "one" and 1 respectively.
during the next iteration, the values get overridden as "two" and "2".
I want to retain the previous values as well. So my output should be myarr1(one,two) myarr1(1,2)
One Star

Re: [resolved] creating and using Arraylists in Talend

So basically i don't want the arraylists being created every time I iterate tjavarow. Looking for a way I can declare the arraylists globally and keep adding values to it.
Moderator

Re: [resolved] creating and using Arraylists in Talend

Hi,
You can use component tjavaFlex to store these values in an Arraylist. In addition, elaborating your case with an example with input and expected output values will help us to give you a precise answer

Why don't you use the component tjavaFlex mentioned in #2. You can created an 2 Arraylists, myarr1(for name) in "Start code", perform a myarr1.add(input_row.name) and myarr2.add(input_row.id) in "Main code" and print out result from "End code".
See my pic
Here is a related forum about the difference between tJavarow and tJavaFlex:Forum 3839
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.
One Star

Re: [resolved] creating and using Arraylists in Talend

Thanks a lot Sabrina. That post really helped!!
The problem was also that I was using tFlowToIterate->tFixedFlowInput to iterate my XML. So it was creating the arraylist for each iteration even in the main section of tjavaflex!
One Star

Re: [resolved] creating and using Arraylists in Talend

So what can be the solution if i have data coming from tFlowToIterate->tFixedFlowInput. Lets say there are multiple values being returned as result from a tXMLRPCInput.
So the job would be like, tXMLRPCInput->tFlowToIterate->tFixedFlowInput.
Even using tJavaFlex will initialize the main and end sections every time and previous values will get overridden. What is the best solution to store these generated values.
Moderator

Re: [resolved] creating and using Arraylists in Talend

Hi,
Using a component tjava to avoid such overridden issue.
See my pics for details.
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.
One Star

Re: [resolved] creating and using Arraylists in Talend

Thanks Sabrina.
So if I use globalMap.put("list",) to store my list, I wont be able to utilize globalMap.put("list",) for storing another list in the same job right?
Moderator

Re: [resolved] creating and using Arraylists in Talend

Hi,
The key in globalMap.put("key", list) is changeable. You can set two globalMaps for your requirement.
See my pic
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.
One Star

Re: [resolved] creating and using Arraylists in Talend

ohh..that's a great feature!! Smiley Happy Thanks a lot for all your help Sabrina.
Moderator

Re: [resolved] creating and using Arraylists in Talend

Hi,
Glad to see that you have got the solution, feel free to post your questions on Talend forum. Smiley Wink
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.
One Star

Re: [resolved] creating and using Arraylists in Talend

Hi,
Can i insert a record in any specific part/portion of a list. For ex- how can i insert a value in the middle of a list?
Thanks,
Riket