Pentaho Tools :

Pentaho C-Tools(CDE,CDF,CDA),Pentaho CE & EE Server,OLAP-Cubes,Analysis using Pivot4J, Saiku Analytics, Saiku Reporting, Ad-hoc Reporting using Interactive Reporting Tool,Dashboards,Reports using PRD, PDD,Data Integration using Kettle ETL,Data Mining usign WEKA,Integration of Servers with Databases,Mobile/iPad compatible Dashboards using Bootstrap Css,Drilldown dashboards,Interactive Dashboards

Friday 13 February 2015

PDI Basics-1 : Command Line Arguments in Pentaho Kettle ETL

In this post we will see the basics on how to work with command line arguments in Kettle ETL.

Software setup : 

Kettle 5.2.0.0 CE

Quick points to Navigate through this post :
1) Command Line Arguments - definition & points

2) Ways to work with Command line arguments
                   1) From command line
                   2) From Kettle GUI

3) Example : With Transformation    
         Scenario : Store argument values(Strings) in a text file

4) Example : With Job  
          Scenario : Store argument values(Strings) in a text file5) Download section 

Download Example here :  Click Me..!!!

Download pdf version of the same article here :  Click Me...!!!! 

Go to "download" tab of this site to get the documents topic wise.  

1) Command Line Arguments :


Command line
Arguments

* A named, user-supplied, single-value input.
* Each transformation or job can have a max of 10 arguments. 
* It is declared as space-separated values given after the Pan or Kitchen line
* Arguments could be numbers, words (strings), or variables 
(system or script variables, not PDI variables).

Reference 

Blog Reference 





2) There are 2 ways to work with command line arguments
1) From command line
2) From Kettle GUI

1) From command line
Command line arguments syntax with transformation 
Win
pan.bat /file:<directory>\<transformation name> arg1 arg2 arg3
Linux
sh pan.sh -file=<directory>/<transformation name> arg1 arg2 arg3

Command line arguments examples with transformations 
Win
pan.bat /file:E:\Explore\Kettle\1_CommandLineArgumentsBasic.ktr 10 20 30
Linux
sh pan.sh -file=/Explore/Kettle\1_CommandLineArgumentsBasic.ktr 10 20 30

Command line arguments syntax with jobs 
Win
pan.bat /file:<directory>\<transformation name> arg1 arg2 arg3
Linux
sh pan.sh -file=<directory>/<transformation name> arg1 arg2 arg3

Command line arguments examples with jobs
Win
kitchen.bat /file:E:\Explore\Kettle\1_CommandLineArgumentsBasic.kjb 10 20 30
Linux
sh kitchen.sh -file=/Explore/Kettle\1_CommandLineArgumentsBasic.kjb 10 20 30

2) From Kettle GUI

l Arguments can be handled at the time of execution of transformation or job.
l In Transformation : At “Execute a Transformation” dialogue window
l Job : At “Excute a Job” dialogue window.

3) Example : With Transformation 
Scenario : Store argument values(Strings or numbers) in a text file

1) Take a new Transformation(Ctrl+N) save it as 1_CommandLineArgumentsBasic.ktr

2) Drag and drop “Get System Info” step from “Input” category.

3) Double click on it get it properties window as shown in below image and Type 3 filed names 
as Arg1,Arg2 and Arg3 and give type as command line argument1 and 2 and 3.

4) Take a “Text output file”  from “Output” category and connect it from “Get Sys Info” step. 

5) Give file path= E:\Explore\Kettle and file name =CommanLineArgumentsOutput and say
  its type = text .. Go to “Fields” tab and click on “Get Fields” button to get the fields coming 
 from “Get System Info” step. 


Execution of transformation
We will see 2 types of executions 
1) Execution from GUI &
2) Execution from command line

Execution from GUI

a) Save the transformation and click on Run button to get it “Execute a transformation window” 
b) In the arguments tab provide 3 arguments as shown in image
c) Now check whether the file is generated with the provided input or not at E:\Explore\Kettle 

Execution from command line
1) Open command prompt and navigate to the folder where you can find pan.bat file
 ( remember to work with transformation on command we need pan.bat file).

2) For example : In my local environment kettle is installed in below location. 
 D:\Softwares Archive Installed\Pentaho\pdi-ce-5.2.0.0-209\data-integration


3) Give below command with your arguments lets say 100 200 300 (space separated arguments) 
as shown in below image. 

D:\Softwares Archive Installed\Pentaho\pdi-ce-5.2.0.0-209\data-integration>
Pan.bat /file:E:\Explore\Kettle\1_CommandLineArgumentsBasic.ktr 100 200 300


 4) Now check whether the output file is updated or not with new arguments. 

4) Example : With Job
Scenario : Store argument values(Strings) in a text file

1) Clt+Alt+N to create a new job and save it as 1_CommandLineArgumentsBasic.kjb

2) Take a START job entry & transformation entry on to the canvas and connect them with HOP. 
In transformation settings give the just 
created transformation path as 
${Internal.Job.Filename.Directory}/1_CommandLineArgumentsBasic.ktr

3)Execution 
Here we can pass command line arguments in 3 ways 
1) GUI execution to give arguments at “Execute a job” window.
2) GUI execution - Provide arguments in “Transformation” entry..(Ignore giving agreements at “Execution a job” window) 
3) Command line arguments 

** GUI execution to give arguments at “Execute a job” window.
1) Save the job and click on Run Button to get “ Execute a job” window..
 Here find Arguments tab and provide values as shown in image 1) Hello 2) Kettle  3) Argument


2) Go back to the file and check for the result...

** GUI execution - Provide arguments in “Transformation” entry..(Ignore giving arguments at “Execution a job” window)
1) As shown in below image go to the transformation entry settings and click on “Arguments” tab 
and give 3 values 
2) Click on “Exucte” button and go back to the file location to check the output. 


The file with newly updated argument values is as follows


** Command line arguments 

1) Open command prompt and navigate to the folder where you can find kitchen.bat file 
( remember to work with jobs on command we need kitchen.bat file).

2) For example : In my local environment kettle is installed in below location. 
 D:\Softwares Archive Installed\Pentaho\pdi-ce-5.2.0.0-209\data-integration


 3) Give below command with your arguments lets say 500 600 700(space separated arguments)
 as shown in below image. 

NOTE :  while passing arguments from command line for job remove arguments in "Transofrmation
entry" if any. Also remove from "Execute a Job" window. 

D:\Softwares Archive Installed\Pentaho\pdi-ce-5.2.0.0-209\data-integration>
Kitchen.bat /file:E:\Explore\Kettle\1_CommandLineArgumentsBasic.kjb 600 700 800


4) Now check whether the output file is updated or not with new arguments. 


 I hope this information will helpful to some one :-)


Command Line Arguments as Place holders in SQL Queries : Read it  here http://diethardsteiner.blogspot.de/2011/03/pentaho-data-integration-scheduling-and.html


 Cheers..!!!








No comments:

Post a Comment