Search code examples
talend

Talend Second Sequence number


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?


Solution

  • You can do it in following way.

    yourInput---tJavaRow---tMap--youroutput

    1. Create context variable named as oldID as int.\
    2. In tJavaRow add following code.

      if(!input_row.ID.equalsIgnoreCase(context.oldID)){ Numeric.resetSequence("i", 0); context.oldID=input_row.ID; }

    3. Add tmap after tJavaRow and add additional column with name COUNTER

    4. In COUNTER column add following code.

      Numeric.sequence("i",1, 1);

    5. 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