Wednesday, February 18, 2015

Kettle Pass parameters from job to transformation in PDI Retrieve data from table by passing table name as parameter

This post will talk about basic understanding of parameters concept in PDI.

Software Setup :
PDI 5.1.0 CE
PostgreSQL

Concept : Retrieve data from table by passing table name as parameter.

You will learn below things
1) Table input step & database connections
2) Creating parameter(s) in Transformation(s) & Job(s)
3) Passing parameter(s) from job to transformation.

Lets say in foodmart database you have below tables 1) region 2) product 3) customer and etc.
Every time when you pass different table name as parameter you should able to fetch the data coming from the passed table.

1) Table input step & database connections
2) Creating parameter(s) in Transformation(s) & Job(s)

1) Create a new transformation & drag and drop "Table Input" step from Design Pane.

2) Double Click on "Table input" step & Click on New tab to give database connections as shown in below image


3) Define the parameter in transformation ( in this example the table name should go as parameter).
    Image A : Right Click on the empty space to get the transformation settings.
    Image B : Database Connection Details

    Parameter Name is : tableName


 4) Come back to the properties of "Table input" & write select statement to retrieve the data.
     Eg : SELECT * FROM product LIMIT 100
     In above example "product" is the table name that you have to replace with the parameter.
     i.e., SELECT * FROM ${tableName} LIMIT 100

     Once you write the query, come down check "Replace variables in script"





 5) Take a "Dummy" step and connect it to "Table input step" . Save the transformation & run it on "Dummy Step"( Right click dummy step and click on "Preview".

OUTPUT : Test 1  : With "region" table

OUTPUT : Result 1


OUTPUT : Test 2 : With "product" table
 * Right click Dummy step then click on Preview
 * Click on Configure & then in parameters tab give "product" for tableName value parameter.
OUTPUT : Result 2 



3) Passing parameter(s) from job to transformation
* Crtl+Alt to create a new job
* From the "General" node of Design tab ( Appears left side) drag and drop "Transoformation step".
* Drag and drop "START" step and connect these two as shown in below image.


* Double click on "Transformation" step to set the properties & parameter information.
* Browse for the transformation file and then move to parameters tab
* Click on "Get Parameters" then you can find parameter get apper under Parameter tab.

* Right click on empty canvas of job to get its settings & move to Parameters tab and give parameter name as "tableName" and provide default value.

Save the job and run it.

IMP NOTE :
1) Parameter names in job & transformation should match.
2) You can create n  number of parameters in job but can pass as many you wish.
3) In job design you should take  "START" step to tell the job to start execution from there.
   If you ignore you will get below error ( which took me awhile to solve it for the very first time).


Start of job execution
:A serious error occurred during job execution: 
Couldnt find starting point in this job.
org.pentaho.di.core.exception.KettleJobException: 
Couldnt find starting point in this job.
at org.pentaho.di.job.Job.execute(Job.java:516)
at org.pentaho.di.job.Job.run(Job.java:422)
Spoon - Job has ended.

References : 
1) http://wiki.pentaho.com/display/EAI/Named+Parameters
2) http://diethardsteiner.blogspot.in/2013/07/pentaho-kettle-parameters-and-variables.html
3) http://wiki.pentaho.com/display/EAI/Substituting+variable+references+in+Job+Parameter+values

Hope this helps some one like me  for the first time who is looking for parameters(named) concept :-)


Cheers :-)

:-) Happy New Year - Welcome - 2015 :-)


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.