Generate a incremental counter based on the key values

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,

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

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download