Steps to create basic task flows in Pentaho
Receiving arguments and parameters in a job:
Jobs, as well as transformations, are more flexible when receiving parameters from outside.
Customizing the hello world file with arguments and parameters:
- Create a new transformation.
- Press Ctrl+T to bring up the Transformation properties window.
- Select the Parameters tab.
- Add a named parameter HELLOFOLDER. Insert Name as the default value.
- Click on OK.
- Drag a Get System Info step to the canvas .
- Double-click the step.
- Add a field named your name. Select command line argument 1 as the Type.
- Click on OK.
- Now add a Formula step located in the Scripting category of steps.
- Use the step to add a String field named message. As Formula, type “Hello, ” & [yourname] & “!”.
- Finally, add a Text file output step.
- Use the step to send the message data to a file. Enter ${LABSOUTPUT}/${HELLOFOLDER}/hello as the name of the file.
- Save the transformation in the transformations folder you created in the previous tutorial, under the name hello_world_param.ktr.
- Open the hello_world.kjb job you created in the previous tutorial and save it under a new job named hello_world_param.kjb.
- Press Ctrl+J to open the Job properties window.
- Select the Parameters tab.
- Add the same named parameter you added in the transformation.
- Click on OK.
- Double-click the Create a folder entry.
- Change the Folder name textbox content to ${LABSOUTPUT}/${HELLOFOLDER}.
- Double-click the Transformation entry.
- Change the transformation filename textbox to point to the new transformation: ${Internal.Job.Filename.Directory}/transformations/hello_world_ param.ktr.
- Click on OK.
- Save the job and run it.
- Fill the dialog window with a value for the named parameter and a value for the command-line argument.
- Click on Launch.
- When the execution finishes, check the output folder. The folder named my_folder, which you initially specified as a named parameter, should be created.
- Inside that folder there should be a file named hello.txt. This time the content of the file has been customized with the name you provided:
Hello, pdi student!
Want to know about Transforming Data with JavaScript? Read this extensive Pentaho Tutorial!
Running jobs from a terminal window:
The transformation also required a command-line argument. When you executed the job from Spoon, you provided both the parameter and the argument in the job dialog window. You will now learn to launch the job and provide that information from a terminal window.
Executing the hello world job from a terminal window:
- Open a terminal window.
- Go to the directory where Kettle is installed.
On Windows systems type:
C:\pdi-ce>kitchen /file:c:/pdi_labs/hello_world_param.kjb Maria -param:"HELLOFOLDER=my_work" /norep
On Unix, Linux, and other Unix-like systems type:
/home/yourself/pdi-ce/kitchen.sh /file:/home/yourself/ pdi_labs/hello_world_param.kjb Maria -param:"HELLOFOLDER= my_work" /norep
- If your job is in another folder, modify the command accordingly. You may also replace the name Maria with your name, of course. If your name has spaces, enclose the whole argument within “”.
- You will see how the job runs, following the log in the terminal:
- Go to the output folder—the folder pointed by your LABS_OUTPUT variable.
- A folder named my_work should have been created.
- Check the content of the folder. A file named hello.txt should be there. Edit the file. You should see the following:
Hello,Maria!
Using named parameters and command-line arguments in transformations:
As you know, transformations accept both arguments from the command line and named parameters. When you run a transformation from Spoon, you supply the values for arguments and named parameters in the transformation dialog window that shows up when you launch the execution. From a terminal window, you provide those values in the Pan command line.
Calling the hello world transformation with fixed arguments and parameters:
- Open the hello_world.kjb job you created in the first section and save it as hello_world_fixedvalues.kjb.
- Double-click the Create a folder job entry.
- Replace the chapter10 string by the string fixedfolder.
- Double-click the transformation job entry.
- Change the Transformation filename as ${Internal.Job.Filename. Directory}/transformations/hello_world_param.ktr.
- Fill the Argument tab as follows.
- Click the Parameters tab and fill it as follows:
- Click on OK.
- Save the job.
- Open a terminal window and go to the directory where Kettle is installed.
On Windows systems type:
C:\pdi-ce>kitchen /file:c:/pdi_labs/ hello_world_param.kjb /norep
On Unix, Linux, and other Unix-like systems type:
/home/yourself/pdi-ce/kitchen.sh /file:/home/yourself/ pdi_labs/hello_world_param.kjb /norep
- When the execution finishes, check the output folder. A folder named fixedfolder has been created.
- In that folder, you can see a hello.txt with the following content:
Hello, reader!
Learn to create advanced transformations in our blog on Creating Advanced Transformations and Jobs!
Running job entries under conditions:
A job may contain any number of entries. Not all of them execute always. Some of them execute depending on the result of previous entries in the flow.
Sending a sales report and warning the administrator if something is wrong:
- As the report will be based on the Jigsaw database you created in Chapter 8, you will need the MySQL server running.
- In order to send e-mails, you will need at least one valid Gmail account. Sign up for an account. Alternatively, if you are familiar with you own SMTP configuration, you could use it instead.