i've got the following data:
ID;NAME;SKILL
1;JOE;XML
1;JOE;JAVA
1;JOE;ORACLE
2;JOHN;JAVA
2;JOHN;API
I need a counter that will give me this structure:
ID;NAME;COUNTER;SKILL
1;JOE;1;XML
1;JOE;2;JAVA
1;JOE;3;ORACLE
2;JOHN;1;JAVA
2;JOHN;2;API
How can i achieve that in Talend? I tried to use a Number.sequence but i dont know how to get the dependency with the column ID. So every time a new id occures i need to reset the Sequence Number.
Any advice?
You can do it in following way.
yourInput---tJavaRow---tMap--youroutput
In tJavaRow add following code.
if(!input_row.ID.equalsIgnoreCase(context.oldID)){ Numeric.resetSequence("i", 0); context.oldID=input_row.ID; }
Add tmap after tJavaRow and add additional column with name COUNTER
In COUNTER column add following code.
Numeric.sequence("i",1, 1);
Now execute your job will get expected output.
my output.
[statistics] connected
1|JOE|1|XML
1|JOE|2|JAVA
1|JOE|3|ORACLE
2|JOHN|1|JAVA
2|JOHN|2|API
[statistics] disconnected