Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I have a certain amount of row and for each group of row I'd like to filter one row according to a series of nested condition.
For example as result of job so far I have multiple groups of lines that look like this :
Column1;Column2;Column3;Column4;Column5
AAAAAA;BBBBBBB;CCCCCCC;DDDDDD;EEEEEEE
AAAAAA;BBBBBBB;CCCCCCC;FFFFFFFF;CCCCCCC
AAAAAA;BBBBBBB;CCCCCCC;DDDDDD;GGGGGG
AAAAAA;BBBBBBB;CCCCCCC;HHHHHH;IIIIIIIIIIIII
Column1 to 3 are keys fr the next table (so only one must remain) and for each groupe I have to pick only one line (for insertion after some more processing) such as
if(Column3 == Column5)
{valid => filter this line and disregard the rest of the group}
else if(Column4 == Column2)
{valid => filter this line and disregard the rest of the group}
else
{there should be at least one line per group so take it anyway}
How can I achieve this with Talend ?
Hi
You can add these logical code on a tJavaRow component, add a flag field for used to filter the rows, for more details, see below screenshot.
tJavaRow code:
output_row.c1 = input_row.c1;
output_row.c2 = input_row.c2;
output_row.c3 = input_row.c3;
output_row.c4 = input_row.c4;
output_row.c5 = input_row.c5;
if(input_row.c3.equals(input_row.c5)){
output_row.isOutput=true;
} else if(input_row.c2.equals(input_row.c4)) {
output_row.isOutput=true;
}else {
output_row.isOutput=false;
}
Let me know if you have any questions.
Regards
Shong
Hello,
First of all, thank you for your answer, but I'm not sure I understand the use of the second tHashOutput and the if link with == 0.
Also, if I understand correctly, if in one of the group there is two lines that each satisfies one of the conditions both will have the isOutput = true and the filter will pass them both.
What I'm trying to get is only one (the row that satisfies uppermost condition) in this case.
If there is no line satisfies the condition, I will use the first line in my scenario, you can see that I use add a sequence number for each line and filter the only the first line in out2 output table, I use runIf trigger to take the first line for each group as your described.
Yes, if two lines that satisfies the condition, both of them are passed, if you want only one line, add a tMap and add a sequence id for each line, filter the first line as I did.
Regards
Shong