Friday 5 April 2013

Converting column data from flat file into row data

 scenario:


Many a times you need to pivot column data into rows.
Consider the below case where source data is like this.

street1  street2  stree3
Alex      Bob     Canny
fedrix    rosey    priya
Jacob    peter    siddle

you need to place them under one group say,street
 

solution:

We can achieve this in two ways:

1.Using Normalizer Transformation
2.Using Java Transformation

Normalize Transformation:

1.import the source into the designer.
2.create a target in the target designer
3.create mapping and name it m_column_to_row_data
4.Import source and target into mapping area.
5.Import Normalizer Transformation.In Normalizer tab create one column with STRING data type and name  it as STREET.give the occurrence as 3.
   Here street is divided in to street1, street2 and street3 ,so occurrence is taken as 3.

Below is the mapping flow:

6.connect ports from SQ to Normalizer transformation and  STREET column from normalizer to Target.
7.Create a workflow and run.

Java Transformation:

Folllow steps 1 to 4  .
Take Java transformation and connect ports from SQ to Java transformation.
In 'O n Input Row' tab write the below code:

street1 = street1;
generateRow();

street1 = street2;
generateRow();

street1 =street3;
generateRow();

 Here is the mapping flow:

Connect street1 form Java transformation to Target. 

Create workflow and run.


Hope this helps.



 

2 comments: