One row into multiple rows

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
dsdevper
Premium Member
Premium Member
Posts: 86
Joined: Tue Aug 19, 2008 9:31 am

One row into multiple rows

Post by dsdevper »

Hi,

Sorry.I dont know how to say..Here i am giving an example of my queastion.

Each columns which has a flag value of '1' or '0' should come as an individual row in the output.

Ex:Input(all feilds are char feilds)

col1 col2 col3 col4 col5 col6
-------------------------------
aa 1 1 1 0 1

bb 0 1 1 1 1

Output should be as(all fields are char)

col1 col2 col3 col4 col5 col6
--------------------------------
aa 1 0 0 0 0
aa 0 1 0 0 0
aa 0 0 1 0 0
aa 0 0 0 0 0
aa 0 0 0 0 1

bb 0 0 0 0 0
bb 0 1 0 0 0
bb 0 0 1 0 0
bb 0 0 0 1 0
bb 0 0 0 0 1


Please any help..

Thanks
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

First thing that comes to mind, use a transformer stage with 5 output links and then funnel them together.

In the first output link, map input columns to col1 and col2, and map zero to the others.
In the second output link, map input columns to col1 and col3, and map zero to the others.

and so on ...

Mike
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Another way is to first use the pivot stage, pivoting on the five "occurrences" of your flag column....this will give you five rows for each "key" with the 1 or 0 .....then set up a counter for each of those keys that goes from 1 to 5, and then have five new columns in a follow up transformer.....each column will have a derivation that looks at the counter to determine if it should get a zero or the value of the (pivoted) flag.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
laknar
Participant
Posts: 162
Joined: Thu Apr 26, 2007 5:59 am
Location: Chennai

Post by laknar »

Hi,

Search with vertical pivot.
Post Reply