From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

Assigning previous row id to next row

Highlighted
Seven Stars

Assigning previous row id to next row

Hi,

I have a table like

item_id,item_name

1,a

1,b

1,c

2,x

2,y

2,z

Now, I want the output to be like: 

surr_key, item_id,item_name, parent_id

1,1,a,-1

2,1,b,1

3,1,c,2

4,2,x,-1

5,2,y,4

6,2,z,5

Here, surr_key is auto_increment and parent_id is the surr_key of precious row for the same item_id.

a is the first item for item_id=1 thus it will be -1 and same with x.

Can anyone help how to achieve it ?

Highlighted
Community Manager

Re: Assigning previous row id to next row

This post answers a slightly different question, but you can use the method to do what you want. Essentially you are looking at the functionality which means that tMap variables are actioned in order from top to bottom and they preserve their values between rows.

 

https://community.talend.com/t5/How-Tos-and-Best-Practices/Compare-row-value-against-a-value-from-th...

Highlighted
Seven Stars

Re: Assigning previous row id to next row

how to do this with integer values, as the compareignorecase accepts string values only
Highlighted
Community Manager

Re: Assigning previous row id to next row

You can use compareTo()  for Integers or == for primitive type ints

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog