Tuesday, 22 April 2014

Padding using Java Transformation

I have a source
Dname
RESEARCH
SERVICE
HR
IT
SALES
PRODUTION
MARKETING
FINANCE

and Target should be

Dname
Length
Max Length
Right Padding
RESEARCH
8
9
RESEARCH*
SERVICE
7
9
SERVICE**
HR
2
9
HR*******
IT
2
9
IT*******
SALES
5
9
SALES****
PRODUTION
9
9
PRODUTION
MARKETING
11
9
MARKETING
FINANCE
7
9
FINANCE**

Solution
The logic is to find the maximum length of the Dname field and make the length of the Right Padding field equal to the maximum length of Dname field by putting '*' at the right.


Algorithm
        1.       Import source
        2.       Pass ports into an expression transformation
        3.       Create one output Port dlength as integer data type in the expression transformation.
        4.       In the expression of dlength port write as length(DNAME). It will give the length of the input dname value.
        5.       Create another output port dummy as integer data type.
        6.       In the expression of dummy port give a value 1.
        7.       Take an aggregator transformation.
        8.       Pass the ports dummy and dlength into aggregator transformation.
        9.       Select Group By check box of dummy.
      10.    Create an output port max_lenght as integer data type.
      11.   In the expression of the max_length port write max(dlength). It will give maximum length of the dlength.
      12.   Checked Sorted input of the aggregator transformation.
      13.   Take a joiner transformation.
      14.   Pass the ports dummy,Dname and dlenght from expression transformation into the joiner transformation and checked Sorted Input in the joiner properties.
      15.   Pass the ports dummy1 and max_length from the aggregator transformation into joiner transformation.
      16.   In the joiner transformation give joiner condition as dummy = dummy1
      17.   Take a java transformation.
      18.   Pass the ports Dname,dlength and max_length from joiner transformation into the Java Transformation.
      19.   In the java transformation create one output port new_dname as string.
      20.   Go to java code tab.
21. Select the Helper Code tab and put the code as



      22.   And go to On Input Row


     23.   Click compile.
     24.   Pass the ports Dname,dlength,max_length and new_dname into the target.

The final mapping will be look like

Then create workflow and run it. That’s all.

No comments:

Post a Comment