Page 1 of 1

Looking for effective solution for sum

Posted: Mon Apr 14, 2014 2:17 am
by vamsi.4a6
I have to find the sum of salaries of all employees and this sum should repeat for all the rows.

The output should look like as
i/p:
employee_id, salary
-------------------------------
10, 1000
20, 2000
30, 3000
40, 5000


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


I am able to achieve the o/p with the help of job sequence by using two jobs after writing
into intermediate file.Just want to know is there any way to get required o/p with one parallel
job?

Posted: Mon Apr 14, 2014 2:49 am
by anbu
What is your input? Table or File?

Posted: Mon Apr 14, 2014 4:25 am
by zulfi123786
1. IF your source is a database handle this in the SQL by generating the sum and joining back to your main source on a ever true condition (1=1)

2. Non Database: you may follow a traditional fork join meathod of taking a copy and then aggregator and then joinin back to second output of copy.

3. If you are using 8.5 you may optionally use looping of transformer (at your risk as you need to store all records in cache and may run out of memory when volume is huge)

Posted: Mon Apr 14, 2014 10:29 am
by soumya5891
What is the version you are using?
If it is 8.5 and above then best option is to use transformer loop with cache memory.

Posted: Mon Apr 14, 2014 11:42 am
by vamsi.4a6
@soumya5891

SOurce is file,version is 8.5

@zulfi123786

Thanks for input.What is the key column i need to mention in aggregator?

Posted: Mon Apr 14, 2014 12:14 pm
by zulfi123786
vamsi.4a6 wrote:What is the key column i need to mention in aggregator?
Looks like you dont have a column to group by ... !!! so what, you can always generate one. have a column generator to generate a dummy column with a static value say 1 and group by on that.

Posted: Mon Apr 14, 2014 2:04 pm
by soumya5891
Also you can achieve by using transformer looping and saveInputRecords() and getSavedInputRecords() function.