row to column

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
rafik2k
Participant
Posts: 182
Joined: Wed Nov 23, 2005 1:36 am
Location: Sydney

row to column

Post by rafik2k »

Input
====
col1 col2 col3
A,B,C,D,E,F,G a,b,c,d,e,f,g P,Q,R,S,T,U,V


Output
====
col1 col2 col3
A a P
B b Q
C c R
D d S
E e T
F f U
G g V

I have implemented this

I have taken input data into a Transformer, where using

Ereplace(DSLink2.inputColumn, ",", CHAR(13):CHAR(10)),

i have converted each input column into as many rows as no. of alphabet in the input column and created 3 output stream for each input column and passed each to different sequential file.
Then next step passing each of these stream to another transformer, where i am generating a dummy id for each stream.

Next two of these streams are passed to two different hash files and one stream to a transformer, where i am joining 3 stream again using id to get output.

For this i have 5 transformers, 2 hash files and 5 sequential files.


seq file1--->Transformer1---->seq file2--->Transformer2----hash file1-----|
|
|----------->seq file3---->Transfomer3----hash file2-- |
| |
------------>seq file4----->Transfomer4------------->Transformer5------>seq file5




Please let me know if is there any better way to acheive the same result?

Thanks in advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Do you know in advance how many rows there will be? Is the change condition a change of case, or the appearance of the space character? That is, could you read into three columns as a space delimited record?

If you could split the file into three based on the space, then you could write the rows into three separate places (files?) with an appropriate key (@INROWNUM from source), and the commas converted to line terminators, and subsequently join these. If you stage them into hashed files, you can use a UV stage to effect the three-way join.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rafik2k
Participant
Posts: 182
Joined: Wed Nov 23, 2005 1:36 am
Location: Sydney

Post by rafik2k »

Code: Select all

Input 
==== 
col1 col2 col3 
A,B,C,D,E,F,G a,b,c,d,e,f,g P,Q,R,S,T,U,V 
It's not displaying values for each column correctly.

The value of col1 is till first space(i.e A,B,C,D,E,F,G ), and the value of col2 is till second space i.e.(a,b,c,d,e,f,g) and for col3 is (P,Q,R,S,T,U,V).

Presently i am creating 3 different seq file for each column. and as i mentioned eariler that for this i have 5 transformers, 2 hash files and 5 sequential files in the job.

I want to know if is there any other approach to do the same.

Moreover i can't predict no. of rows in the source.

Please advise.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Did you try the approach I outlined in my second paragraph?
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