Monday, September 1, 2014

RIGHT AND LEFT FUNCTIONS IN TRANSFORMER STAGE WITH EXAMPLE



RIGHT AND LEFT FUNCTIONS IN TRANSFORMER STAGE WITH EXAMPLE
For example some times we get the data from warehouse as below

This is just a sample example data


Customers
1 vanitha 2000
2 ramesh 2300
3 naresh 2100
4 kiran 1900
5 sunitha 2000


They are exactly straight. They just have spaces in between the data.

Our requirement is to get the data into the three different columns from

single column.

Here The data is customers is the column name we are getting and we have only

single column.

Now Take Job Design as below

Seq.File------------Tx-------------Ds


Read the data in Seq.file

and dont forget to tick first line is column name.


In Transformer stage Create 3 columns and write the expressions in derivations.

Create Columns as c_id , c_name, c_sal

You can create the names as your wish.

Expressions for three columns are

left(dslink3.customers,1) for c_id

right(left(dslink3.customers,8),7) for c_name

right(dslink3.customers,4) for c_sal


That's it

Give name for the file in the Target.


Now Compile and Run the Job.

You will get the Output as required

1 comment:

Unknown said...

This approach will only work as far as having a single character in the id field. If there are two digits then the second digit is passed to the next column. I found it works better if using the Field function as such:

Field(DSLink44.Customers," ",1,1)
Field(DSLink44.Customers," ",2,1)
Field(DSLink44.Customers," ",3,1)

Hope this helps someone.