Need Repetition of rows

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
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Need Repetition of rows

Post by moulipx »

Hi All,

I need your help in implementing the below requirement in datastage

Iam having 3 columns in a sequential file with comma delimeter.And i need to write into one sequentail file..

And my testdata is ::

1A,aaa,1
2A,bbb,2
3A,cccc,3
4A,ddd,1

And i need to produce the ouput based on third column value.If the third column value contains 1 i need one copy of the row.If it contains 2 i need 2 copies of that row..
1A,aaa,1
2A,bbb,2
2A,bbb,2
3A,cccc,3
3A,cccc,3
3A,cccc,3
4A,ddd,1

Thanks in advance
Chandra Mouli
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Put the following in the filter command of the sequential file stage

Code: Select all

awk -F"," '{for (i=1; i<=$3; i++) {print $0}}'
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

Thanks for your reply.

Can we implement this logic in transformer?
Chandra Mouli
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Yes you can. You will have to cook up a custom C routine that you can call from within the transformer. The C routine will do exactly what my awk script is doing, strip out the third column and run a loop to duplicate the row that many number of times.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

... or you could upgrade to 8.5 where they've implemented "transformer looping". :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

So transformer looping is finally here. That is so cool.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

Prior to version 8.5 the lookup stage is one of the easiest ways to multiple or clone input rows.

Create a text file with the following values:
Key
1
2
2
3
3
3
4
4
4
4
etc

Join to this in a lookup stage using the Key field linked to the input counter field and set the combo box property to make this a multi value lookup. This will give you multiple output rows based on the number of lookup rows found.
Post Reply