Looking for effective solution for sum

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Looking for effective solution for sum

Post 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?
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

What is your input? Table or File?
You are the creator of your destiny - Swami Vivekananda
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post 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)
- Zulfi
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post 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.
Soumya
vamsi.4a6
Participant
Posts: 334
Joined: Sun Jan 22, 2012 7:06 am
Contact:

Post 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?
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post 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.
- Zulfi
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

Also you can achieve by using transformer looping and saveInputRecords() and getSavedInputRecords() function.
Soumya
Post Reply