Seven Stars

[resolved] Can tJavaRow be used to filter rows or create multiple rows

Is it possible to use tJavaRow to filter out a row or to create multiple rows from one?
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] Can tJavaRow be used to filter rows or create multiple rows

Hi
Yes, it looks very inefficient and nasty to maintain, but it based on your project request, because sometimes,we will repeat the row many times based on the value of one field, not simply repeat the same row many times. For exmaple:
id;name;number
1;shong;3
2;alevy;4
I hope repeat the row many times based on the number filed and the result will be something like this:
id;name;number
1;shong;3_1
1;shong;3_2
1;shong;3_3
2;alevy;4_1
2;alevy;4_2
2;alevy;4_3
2;alevy;4_4
So, I use tFlowToIterate to iteate each and store each value of field to global vars, perhaps I will do some conculation and operation on each value.
Of course, if you just want simply repeat the same row many times, as you said, use a delimiter to concatenate the row many times on tJavaRow as you want and then tNormalized the row based on item separator defined by you.
For example
tRowGenerator--tJavaRow--tNormalize--(tExtractDelimitedFileds if need)--tLogRow
please my screenshots.
code on tJavaRow:
output_row.line=null;
for(int i=1;i<3;i++){
if(output_row.line==null){
output_row.line=input_row.id+";"+input_row.name;
}else{
output_row.line=output_row.line+"@"+input_row.id+";"+input_row.name;
}
}

Also, would it not be better to use tIterateToFlow instead of tFixedFlowInput?

In this case, both of them are used to generate a row.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
4 REPLIES
Four Stars

Re: [resolved] Can tJavaRow be used to filter rows or create multiple rows

I don't know , but there is tFilterRow
Community Manager

Re: [resolved] Can tJavaRow be used to filter rows or create multiple rows

Hello Alevy
To filter out a row, use tFilterRow, to create multiple rows, we ususally use tFlowToIterate--tLoop---tFlowFixedInput to iterate each row and generate multiple rows based on this row.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Seven Stars

Re: [resolved] Can tJavaRow be used to filter rows or create multiple rows

Thanks for your response, shong.
So, if I understand your suggestion correctly, effectively every field from your original flow gets dumped to global variables by tFlowToIterate and then has to be retrieved for each loop by tFixedFlowInput (with globalMap.get calls) and that happens for each row in the original flow? That seems very inefficient...
Based on your suggestion, if I need the row multiplication to be conditional (i.e. to only multiply some rows and to multiple some rows a different number of times) I would include the appropriate expression in the "To" field of tLoop?
Also, would it not be better to use tIterateToFlow instead of tFixedFlowInput?
Community Manager

Re: [resolved] Can tJavaRow be used to filter rows or create multiple rows

Hi
Yes, it looks very inefficient and nasty to maintain, but it based on your project request, because sometimes,we will repeat the row many times based on the value of one field, not simply repeat the same row many times. For exmaple:
id;name;number
1;shong;3
2;alevy;4
I hope repeat the row many times based on the number filed and the result will be something like this:
id;name;number
1;shong;3_1
1;shong;3_2
1;shong;3_3
2;alevy;4_1
2;alevy;4_2
2;alevy;4_3
2;alevy;4_4
So, I use tFlowToIterate to iteate each and store each value of field to global vars, perhaps I will do some conculation and operation on each value.
Of course, if you just want simply repeat the same row many times, as you said, use a delimiter to concatenate the row many times on tJavaRow as you want and then tNormalized the row based on item separator defined by you.
For example
tRowGenerator--tJavaRow--tNormalize--(tExtractDelimitedFileds if need)--tLogRow
please my screenshots.
code on tJavaRow:
output_row.line=null;
for(int i=1;i<3;i++){
if(output_row.line==null){
output_row.line=input_row.id+";"+input_row.name;
}else{
output_row.line=output_row.line+"@"+input_row.id+";"+input_row.name;
}
}

Also, would it not be better to use tIterateToFlow instead of tFixedFlowInput?

In this case, both of them are used to generate a row.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business