Pivot Functionality

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
ramukds
Premium Member
Premium Member
Posts: 20
Joined: Thu Oct 18, 2007 8:42 pm
Location: Chicago

Pivot Functionality

Post by ramukds »

Hello,
Can Pivot be used for an example like below;

Input

Field 1, Field2
p1 u1,u2
p2 u3,u4

Note: Field 2 has multiple values seperated by ','.


Required Output

Field1 Field2
p1 u1
p1 u2
p2 u3
p2 u4
etldwh_techie2050
Participant
Posts: 9
Joined: Mon Jun 29, 2009 4:27 pm

Post by etldwh_techie2050 »

ramku, horizontal pivot is only possible and not the vertical. You have to apply some other logic but cannot use pivot stage for your purpose.
muito obrigado!
etldwh_techie2050
syed_haji_1201
Participant
Posts: 2
Joined: Thu Nov 20, 2008 6:06 am
Location: hyderabad

Re: Pivot Functionality

Post by syed_haji_1201 »

Hi,

Just Make use of stage variable and after that use pivot stage.

Regards
H
shivakumar
Participant
Posts: 31
Joined: Wed Mar 17, 2004 3:33 am

Post by shivakumar »

Hi ,

Use the Column Import Stage in that Import Input Column=Field2 and in the Output define the columns as Filed3 and Filed4 and in the Output Format Tab final delimeter as 'none' and filed defalts as 'Comma' after that use the pivot stage.

In this method no need to use the Transformer.

Flat File ----->Column Import Stage--- >Pivot Stage--->Flat File.

Regards
Siva
ramukds
Premium Member
Premium Member
Posts: 20
Joined: Thu Oct 18, 2007 8:42 pm
Location: Chicago

Post by ramukds »

Shiva,

Field 2 is dynamic. It could have values u1,u2,u3....
shivakumar wrote:Hi ,

Use the Column Import Stage in that Import Input Column=Field2 and in the Output define the columns as Filed3 and Filed4 and in the Output Format Tab final delimeter as 'none' and filed defalts as 'Comma' after that use the pivot stage.

In this method no need to use the Transformer.

Flat File ----->Column Import Stage--- >Pivot Stage--->Flat File.

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

Post by chulett »

'Dynamic' is fine as long as you know or can define a maximum number of columns to pivot - can you?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ramukds
Premium Member
Premium Member
Posts: 20
Joined: Thu Oct 18, 2007 8:42 pm
Location: Chicago

Post by ramukds »

Craig,

Thats the issue...we dont know the maximum...it could vary.

chulett wrote:'Dynamic' is fine as long as you know or can define a maximum number of columns to pivot - can you? ...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So you can't even make a reasonable guess as to how many it might have as a maximum? I understand it will vary, that's fine, you're certain there is no effective upper boundary? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ramukds
Premium Member
Premium Member
Posts: 20
Joined: Thu Oct 18, 2007 8:42 pm
Location: Chicago

Post by ramukds »

Craig,
I was trying make it as scalable as possible. Any ways if we define 5 as the upper boundary, I guess the data has to be appended with 3 commas
to the following row inorder to read it. Correct me if I am wrong if you think there is other workaround

Incoming:p1 u1,u2.

Data Modification to read it: p1 u1,u2, , , .

chulett wrote:So you can't even make a reasonable guess as to how many it might have as a maximum? I understand it will vary, that's fine, you're certain there is no effective upper boundary? :? ...
shivakumar
Participant
Posts: 31
Joined: Wed Mar 17, 2004 3:33 am

Post by shivakumar »

Hi,

Without knowing the Max Count it is not possible to define the output columns..

If you are thinking that the max values you can receive for the Field2 as 5 then define 5 output columns in the column import stage and propagate the columns to the pivot stage..

Cheers
Siva
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You have options to choose from - something like

1.) using external script like awk
2.) crossing with a dummy row generator and to extract individual values
3.) build op
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

4.) Using Sort stage, Transformer stage and Remove Duplicates 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.
Post Reply