Generate a incremental counter based on the key values

Highlighted
One Star

Generate a incremental counter based on the key values

Need help with configuring this scenario.
I have Delimited File with ID and data associated with it. And I have DB2 table with ID and SeqNbr as primary key and data columns. While reading Delimited File and inserting to DB2 I need to generate SeqNBr.
Sample of how the Delimited file looks:
ID
-----
ABC
ABC
ABC
XYZ
XYZ
DEF
LMN
LMN
Here is how I need to generate Seq nbr
ID      SeqNBR
-----  ----------
ABC   1
ABC   2
ABC   3
XYZ   1
XYZ   2
DEF   1 
LMN  1
LMN  2
Can you please suggest how to achieve this?
Thanks,

Highlighted
Ten Stars

Re: Generate a incremental counter based on the key values

This can be achieved with a tJavaFlex and a HashMap. It will require a bit of Java code. You need to instantiate the HashMap in the Start Code section. Then in the Main Code section, for every row you will check the HashMap to see if the ID exists in the HashMap. If it does, then you will retrieve the count, add 1 to it and put it back into the HashMap. If it does not exist, you will add it to the HashMap with a value of 1. 
Highlighted
One Star

Re: Generate a incremental counter based on the key values

Thank You. I tried using TJavaRow and it worked with little bit of coding.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog