Vertical Pivot without any grouping column

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
abhik05
Participant
Posts: 28
Joined: Thu Mar 08, 2012 8:31 am

Vertical Pivot without any grouping column

Post by abhik05 »

I have input data coming as :
In_Field A
-----------
1a
2e
3f
7h
8t
.
.
.
n

I need to map this input field value to 3 separate output fields.
Ot_FieldA Ot_FieldB Ot_FieldC
--------------------------------------
1a 2e 3f
7h 8t ....
... .... ....

I dont have any input field to group by the set (3 rows).

Please help.
Abhik.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Create a grouping column then pivot. It can be as simple as a number you increment every 3 rows and then drop post-pivot. Be careful with your partitioning, of course. If you are on 8.5+ you could use transformer looping for this rather than the Pivot stage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bhasds
Participant
Posts: 79
Joined: Thu May 27, 2010 1:49 am

Post by bhasds »

Hi Abhik05,

You may try this through transformer-

step 1-

take 2 stage variable-

Code: Select all

If DSLink105.col1 <> SV1 Then SV1:" ": DSLink105.col1 Else @FALSE   SV1

@PARTITIONNUM + (@NUMPARTITIONS * (@INROWNUM - 1)) + 1     SV2
step2- In derivation constraint-

Code: Select all

Mod(SV2,3) ="0"
step3- deriavtion

Code: Select all

Field(Field(SV1," ", (Dcount(SV1," ")-3)+1, Dcount(SV1," "))," ",1)   col1

Field(Field(SV1," ", (Dcount(SV1," ")-3)+1, Dcount(SV1," "))," ",2)  col2

Field(Field(SV1," ", (Dcount(SV1," ")-3)+1, Dcount(SV1," "))," ",3)  col3
PhilHibbs
Premium Member
Premium Member
Posts: 1044
Joined: Wed Sep 29, 2004 3:30 am
Location: Nottingham, UK
Contact:

Post by PhilHibbs »

If you're going with a Transformer based approach, remember to include "Or LastRow()" in the output constraint in case your data doesn't have an exact multiple of three rows.

I'm not sure I like the idea of concatenating with spaces and then splitting. I'd rather gather the values in three Stage Variables. Just because the example doesn't have spaces, doesn't mean that the data never will. Why not concatenate with and split on an 'x' because, after all, none of the examples have an 'x' in them!

Also, I feel the need to reiterate chulett's warning about partitioning. The premise of your problem practically precludes partitioning, so you may have to use Sequential execution mode, a Node Map constraint, or partitioning on a fixed value.
Phil Hibbs | Capgemini
Technical Consultant
Post Reply