Four Stars

Need to refer to a set of rows from the flow in a tJavaFlex

I have a job where I create a set of row, using tMySQLInput. I need to be able to iterate thru these rows in a tJavaFlex component, but I can't figure out how to refer to them inside the tJavaFlex.
I need to be able to iterate the whole set of rows - for instance, I know that I can work on rows in the tJavaFlex as they come one at a time, but how to refer to a set of rows (created in the same job) using "for each" constructs in the tJavaFlex?
Thanks for any pointers!
8 REPLIES
Community Manager

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Hi
Iterate the whole set of rows? Maybe you need the tFlowToIiterate component, can you offers us more information what you want to do ? So that we can give you precise answer.
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Yes, iterate the whole set of rows (it's a small number of rows). I need to take the rows and in the tJavaFlex component, do a for each on them in in order to put them into a application-defined java collection. Once they are in there, I execute a method to get a (true/false) result.
The idea is that we have existing java code that evaluates some specific result, but it wants things set up in a particular way before the call. The rows will have the data needed, but I can't figure out how to put a set of rows into some form where it would be possible to "for each" them in the tJavaFlex component.
I could do something stupid previous to the tJavaFlex, like join all the rows together and then split them in the tJavaFlex, but is there a better way?
Community Manager

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Hi
Let's take an example, assuming you are trying to put each row into a List:
tMysqlInput--row1--tJavaFlex
In the begin part of tJavaFlex, define a list:
java.util.List list=new java.util.ArrayList();
in the main part of tJavaFlex, add each row to the list:
list.add(row1.columnName)
in the end part of tJavaFlex, use the list as a paramter to execute a method:
Boolean result=methodName(list);
or store the list to a global variable for use later:
globalMap.put("keyName", list):
If it does't match your request, please show us an example code you are writing in tJavaFlex component, so that we can understand you more clear.
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Ah so probably I am misunderstanding the sequence of events. If I have a job like the one you describe: tMysqlInput--row1--tJavaFlex -- rest of flow...
I thought that the java inside tJavaFlex would only execute one row at a time - for instance along comes row 1 from the tMysqlInput, into the tJavaFlex. And then:
1. row gets added to my ArrayList
2. Boolean result is evaluated in tJavaFLex
3. result is passed to following component
... and then repeat for each row.
But instead, if I understand what you're saying, it sounds like the main part of the tJavaFlex is executed for each incoming row, thereby providing a way to accumulate the rows into the ArrayList, and then in the end part of the tJavaFlex, I make the call to the method.
Is that right?
Community Manager

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Hi
Yes, the main part of tJavaFlex is executed for each incoming row, the begin part execute only one time before tMysqlInput works, and the end part of tJavaFlex execute only one time after all the rows are processed.
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Wow.. thank you shong! I think this task will be much easier now that I understand
Four Stars

Re: Need to refer to a set of rows from the flow in a tJavaFlex

You said "and the end part of tJavaFlex execute only one time after all the rows are processed" ... is it possible to output any more additional rows, in the end part of the tJavaFlex component?
The problem that I have is: in the incoming rows, the first row needs to be looked up in the rest of the rows. For example, 10 rows enter the tJavaFlex component. In the main part of the component, I put row 1 into one ArrayList, and then the rest of the 9 rows into another ArrayList. This is done with an "if" statement in the main part.
Since the main part is called for each row, once we get to the end part of the tJavaFlex it's time to now call some utility, passing the two nicely populated ArrayLists as parms. But then when I try to output a row with the result from calling the utility, there is no error, but no result row either.
It looks like once the end part starts executing, all the rows have already zoomed past and the output is done. Is there somewhere where I can put the result row so that I can get at it in a following stage?
Thanks for your patience :-)
PS: The only reason that I'm creating these two Arraylists like this is because I could not find a way to prepare the 2 sets of data ahead of time in a way that the tJavaFlex can operate on them. I tried tMemorizeRows, but that didn't seem to work. I can change this design to whatever would be more appropriate if required - maybe a subjob, maybe 2 tJavaFLex components, etc. The basic need to is to be able to get at 2 sets of data, and call external routines using these 2 sets, and output a result into the flow.
Community Manager

Re: Need to refer to a set of rows from the flow in a tJavaFlex

Hi
At the end part of tJavaFlex, store the resutl to a global variable for use later. Afterwards, you can use tFixedFlowInput to generate one input data flow with "OncomponentOK" after tJavaFlex
----------------------------------------------------------
Talend | Data Agility for Modern Business