Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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.
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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!

View solution in original post

12 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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)
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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: https://community.talend.com/t5/Design-and-Development/instance-row1-inside-tjavaflex-Urgent/td-p/82...
Best regards
Sabrina
0683p000009ME3V.png
Anonymous
Not applicable
Author

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!
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

Hi,
Using a component tjava to avoid such overridden issue.
See my pics for details.
Best regards
Sabrina
0683p000009MDgm.png 0683p000009ME5G.png
Anonymous
Not applicable
Author

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?
Anonymous
Not applicable
Author

Hi,
The key in globalMap.put("key", list) is changeable. You can set two globalMaps for your requirement.
See my pic
Best regards
Sabrina
0683p000009MDHO.png