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
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

vertical pivot

Post by sainath »

Hi

I want to convert data from rows to columns for same key value .It can have N number of values .
Input
Key
1 a
1 b
1 c
1 to N
Output
1 a:b:c

I cannot use vertical pivot because I dont know array size.

I also tried to transformation loop with loopvar <= MAX(COUNT) .But it is looping same value

Can you share your ideas

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

Post by chulett »

You would use Transformer Looping to go the other direction, columns to rows. This is transformer concatenation and Remove Duplicates, retaining the last duplicate.

Edited to clarify the fact that by 'aggregation' I meant aggregate the values in the transformer via concatenation, not the stage of the same name.
Last edited by chulett on Sat Apr 26, 2014 7:54 am, edited 2 times in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ssnegi
Participant
Posts: 138
Joined: Thu Nov 15, 2007 4:17 am
Location: Sydney, Australia

Reply

Post by ssnegi »

Transformer : Key hash partition sort ascending
Value (a,b,c etc) No partition Sort only ascending
Stage Variables :
svValue : if svKey = Input.Key then svValueOld:':':Input.Value else Input.Value
svKey : Input.Key
svValueOld : svValue

Then Remove Duplicate stage with Same partition.
Key : Key Duplicate to retain : Last.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Reply

Post by chulett »

ssnegi wrote:Stage Variables :
svValue : if svKey = Input.Key then svValueOld:':':Input.Value else Input.Value
svKey : Input.Key
svValueOld : svValue
You only need two as there's no need to save the 'old' value, just the key:

Code: Select all

svValue:  if Input.Key = svKeyOld then svValue:':':Input.Value else Input.Value 
svKeyOld: Input.Key
And a key change column would allow the use of a single stage variable.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

Post by sainath »

Hi

Thanks for your reply.My mistake I did not explain correclty on my previous email .I updated my requirement .I will have different keys.


Some how i have to add a logic to only append the rows when there is same key .

Input
Key
1 a
1 b
1 c
1 to N
2 a
2 b
2 c
2 to N
Output
1 a:b:c
2 a:b:c


thks
RPhani
Participant
Posts: 32
Joined: Sun Aug 26, 2012 7:03 am
Location: Hyd

Post by RPhani »

Hi,

I think the same code work for your scenario.

--------------------------------------
Phani
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Exactly... doesn't change the answer.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sainath
Premium Member
Premium Member
Posts: 138
Joined: Fri Nov 19, 2004 3:57 pm

Post by sainath »

HI

Thanks for reply .Your solution worked
Post Reply