Assigning previous row id to next row

Highlighted
Five 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 ?

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

Five Stars

Re: Assigning previous row id to next row

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

Re: Assigning previous row id to next row

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

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

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog