Page 1 of 1

row to column

Posted: Mon May 14, 2007 12:49 am
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

Posted: Mon May 14, 2007 1:16 am
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.

Posted: Mon May 14, 2007 2:11 am
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.

Posted: Mon May 14, 2007 4:09 pm
by ray.wurlod
Did you try the approach I outlined in my second paragraph?