String Concatenation based on Keys

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
dganeshm
Premium Member
Premium Member
Posts: 91
Joined: Tue Aug 11, 2009 3:26 pm

String Concatenation based on Keys

Post by dganeshm »

052288064081042322OCT08TUL300AA3151MAINT ENTRY. AIRCRAFT NEEDS LMP DOWNGRADE DUE TO AUTOLAND IN 60 DAYS ******************** MEL
052288064081042322OCT08TUL300AA3151 *RESTR TO CAT I*. DUE TO 60 DAY EXCEEDENCE OF THE F.C.C
The key here is
052288064081042322OCT08TUL300AA3151

based on this I wanted to concatenate the Text field... please suggest on how to do this..
Regards,
Ganesh
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Make sure that your data are partitioned on the key.

Sort the data by key, generating a Key Change column. If the data are already sorted, indicate this fact in the Sort stage.

In a Transformer stage stage variable maintain the concatenated string.

Code: Select all

If KeyChanged Then input.String Else svConcatenatedString : " " : input.string
Downstream of the Transformer stage use a Remove Duplicates stage to preserve only the last record for each key value.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

ray.wurlod wrote:Downstream of the Transformer stage use a Remove Duplicates stage to preserve only the last record for each key value.
If you're on version 8.5 or higher, could you use the LastRowInGroup() function in the Transformer constraint to avoid a Remove Duplicates stage? You may also be able to avoid generating or testing a key change column, if you tested on LastRowInGroup() and altered the stage variable logic a bit. I think it should be possible, but I haven't tested it.
Last edited by qt_ky on Thu Jan 12, 2012 10:44 pm, edited 1 time in total.
Choose a job you love, and you will never have to work a day in your life. - Confucius
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

Or the pivot stage? (Maybe assuming 8.5 again as can't remember what 8.1 offered)
dganeshm
Premium Member
Premium Member
Posts: 91
Joined: Tue Aug 11, 2009 3:26 pm

Post by dganeshm »

Created a CHECKSUM based on the keys and then used a stage variable in the Transformer stage and concatenated the strings. And used a remove duplicates stage to retain the last one.
Regards,
Ganesh
Post Reply