Vertical Pivot

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
Ram1234
Participant
Posts: 3
Joined: Sun Sep 19, 2010 7:52 pm
Location: Ram1234

Vertical Pivot

Post by Ram1234 »

Hi All,

I know there are tons of topic's on reverse pivoting but then i didn't get any clear understanding on the solution. Can any please help me out on my issue.

Input :

ID Name
1 John
1 Mike
2 Rita
2 Ray
1 Boy

Output :

ID Name1 Name2 Name3 Name4
1 JOHN MIKE BOY NULL
2 RITA RAY NULL NULL

I guess this can be achieved using stage variable's but not sure how to do...can someone please help me out...

Thanks in advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Any chance you could use a Server job for this? That would make it trivial. Otherwise you need sorted input & group change detection via stage variables to perform this feet, that and probably a known 'end of data' record added to the stream to pop out the last group.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Ram1234
Participant
Posts: 3
Joined: Sun Sep 19, 2010 7:52 pm
Location: Ram1234

Post by Ram1234 »

first of all thanks for the reply.....i can not use server job....I can implement it in a lookup in server jobs ...but not sure how to do in parallel jobs
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Sort by ID, generating a key change column.
Based on the key change value, in a Transformer stage either accumulate a delimited list of values or begin a new record.
Downstream of the Transformer stage use a Remove Duplicates stage to preserve only the last of each group.
You're pretty much done at this point. You could write to a CSV file directly. Otherwise you may need to re-parse the data (Column Input stage or Transformer stage) into your arbitrary number of output columns. Of course, the smart approach is to have "sufficient" columns for all cases and populate the remainder after parsing the ones you have with "" or NULL.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah, yes... remove duplicates. No need for a silly trailer record. And here I'd just done something similar in that other tool using a Aggregator to capture the last() record from each group. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Ram1234
Participant
Posts: 3
Joined: Sun Sep 19, 2010 7:52 pm
Location: Ram1234

Post by Ram1234 »

hmm...let me try and get back to you...Thanks a lot for the help
Post Reply