Page 1 of 1

Getting Next row value and cumulative value for all i/p recs

Posted: Tue Oct 30, 2012 2:11 pm
by saikirang
Could you please help me out on this.

Input -
employee_id, salary
-------------------
10, 1000
20, 2000
30, 3000
40, 5000

1) Create a job to get the next row salary for the current row. If there is no next row for the current row, then the next row salary should be displayed as null.

The output should look like as

employee_id, salary, next_row_salary
------------------------------------
10, 1000, 2000
20, 2000, 3000
30, 3000, 5000
40, 5000, Null


2) Create a job to find the sum of salaries of all employees and this sum should repeat for all the rows.

The output should look like as

employee_id, salary, salary_sum
-------------------------------
10, 1000, 11000
20, 2000, 11000
30, 3000, 11000
40, 5000, 11000

Posted: Tue Oct 30, 2012 7:01 pm
by ray.wurlod
1) Sort data in reverse order and use stage variables in Transformer stage to "remember" previous row value. If necessary re-sort after Transformer stage.

2) This is a classic 'fork join' design. Use a Copy stage to split your data stream into two. One stream runs through an Aggregator stage to perform the sum. Downstream of that join the two streams together using a dummy constant key generated upstream of the Copy stage (for example using Column Generator stage with a cycle containing one value).

Posted: Tue Oct 30, 2012 10:23 pm
by saikirang
Thanks Ray for your quick response ..

Could some one please paste the reply given by Ray as I'm not yet a premium member ... thank you so much!!

Posted: Tue Oct 30, 2012 10:30 pm
by chulett
Sorry but that's not the way it works around here and if anyone does I'll just delete it.

How about this? Tell us what you've tried so far and what issues you've faced. Failing that, ideas you've had on how to approach this. That rather than simply coming here and pasting in nothing more than the requirements you've been given to develop two jobs.

Posted: Wed Oct 31, 2012 5:48 pm
by saikirang
Craig - I did try few options which I thought were not best methods / optimal solutions to achieve it. hence, I asked for some suggestions .... Thanks for your feedback ... henceforth, i will post my approaches as well...

I tried another option which worked well. I used 'transformer' looping options to achieve this using "SaveInputRecord() & GetSavedInputRecord()" functions.

It would be great if you could let me know what Ray mentioned in the previous post ... Thanks again!!