Can we do sum in transformer stage?If yes how?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

sureshchandra
Participant
Posts: 92
Joined: Mon May 07, 2007 4:26 am

Can we do sum in transformer stage?If yes how?

Post by sureshchandra »

Hi,
Can we do aggregation(sum) in transformer stage.If yes pls help me how to do?


thanks in advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Stage variable initialized to zero and added to as each row arrives on the input link.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

hello ray, please can you check what is issue with this code.

SQL> select deptno from emp order by deptno;

DEPTNO
----------
10
10
10
20
20
20
20
20
30
30
30

DEPTNO
----------
30
30
30

14 rows selected.

i have 2 stage variables val1 and val2 both initialized to 0.

job design is like oci--->transformer--->hash file.


in transformer i have done


derivation stage variable
------------------------------------------
DSLink2.deptno val1

If DSLink2.deptno =val1 Then val2
val2+1 else '0



output i have two columns deptno and val2.

my output shows like

deptno val2

10 3
20 8
30 14.


please guide me.
baglasumit21
Participant
Posts: 132
Joined: Wed Mar 01, 2006 11:12 pm
Location: Pune

Re: Can we do sum in transformer stage?If yes how?

Post by baglasumit21 »

sureshchandra wrote:Hi,
Can we do aggregation(sum) in transformer stage.If yes pls help me how to do?


thanks in advance
Yes it can be done in a transformer stage. You need to play around with the stage variables. Be sure that the source data is sorted on the keys you wish to aggregate on and then use stage variables to compare the key columns and sum the values for column if the key column are same.
SMB
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your original question did not mention grouping. Therefore I answered in the sense of a simple sum. You need sorted input and more stage variables to identify when the groups change so that you can reset the summation variable.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sureshchandra
Participant
Posts: 92
Joined: Mon May 07, 2007 4:26 am

Post by sureshchandra »

Hi Ray,
thanks for ur response.
i have to do sum in Transformer.For eg:A+B=C.
Here A and B are columns which are there and C is the new column(sum(A+B)).So C is the new column i have to insert .


thanks in advance
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

yes it can be done
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

And, to clarify your requirement, you want a separate sum for each combination of A and B. Is that correct?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sureshchandra
Participant
Posts: 92
Joined: Mon May 07, 2007 4:26 am

Post by sureshchandra »

Hi all,
Thanks for ur help.Issue is resolved.
baglasumit21
Participant
Posts: 132
Joined: Wed Mar 01, 2006 11:12 pm
Location: Pune

Post by baglasumit21 »

sachin1 wrote:hello ray, please can you check what is issue with this code.

SQL> select deptno from emp order by deptno;

DEPTNO
----------
10
10
10
20
20
20
20
20
30
30
30

DEPTNO
----------
30
30
30

14 rows selected.

i have 2 stage variables val1 and val2 both initialized to 0.

job design is like oci--->transformer--->hash file.


in transformer i have done


derivation stage variable
------------------------------------------
DSLink2.deptno val1

If DSLink2.deptno =val1 Then val2
val2+1 else '0



output i have two columns deptno and val2.

my output shows like

deptno val2

10 3
20 8
30 14.


please guide me.
Hi Suresh
Try this
derivation stage variable
------------------------------------------

if DSLink3.DEPTNO = stageVar2 Then StageVar1+1 else 1 StageVar1
DSLink3.DEPTNO StageVar2

This will give you the result as

10 1
10 2
10 3
20 1
20 2
20 3
20 4
20 5
30 1
30 2
30 3
30 4
30 5
30 6

Then you can write this output to a hash file with the dept_no as key
you will ge tthe output as

10 3
20 5
30 6.
SMB
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

thanks a lot
cpvnprasad
Participant
Posts: 5
Joined: Fri Mar 14, 2008 9:57 am
Location: hyd

Post by cpvnprasad »

Hi

I have another idea for this,there is an inbuilt aggregator which we will get the same result as you are looking for.
Thanks
Naresh
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If it is resolved please mark the thread as Resolved.

cpvmprasad, the original question was very specific about "in Transformer stage".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
thurmy34
Premium Member
Premium Member
Posts: 198
Joined: Fri Mar 31, 2006 8:27 am
Location: Paris

Post by thurmy34 »

Hi,
When i have to do this i use RowProcCompareWithPreviousValue.
Hope This Helps
Regards
cpvnprasad
Participant
Posts: 5
Joined: Fri Mar 14, 2008 9:57 am
Location: hyd

Post by cpvnprasad »

Hi to all

Ray,i have done in the transformer stage itself.

actually the same problem i have faced previously,
by doing the same way i have done it...

Thanks
Thanks
Naresh
Post Reply