PenPentaho Tutorialaho Tutorial
PenPentaho Tutorialaho Tutorial
Audience
This tutorial is designed for all those readers who want to create, read, write, and modify
Dynamic Reports using Java. In addition, it will also be quite useful for those readers who
would like to become a Data Analyst.
Prerequisites
Before you start proceeding with this tutorial, we assume that you have prior exposure to
Core Java, Database Concepts, and SQL Queries.
Pentaho
Table of Contents
About the Tutorial .................................................................................................................................... i
Audience .................................................................................................................................................. i
Prerequisites ............................................................................................................................................ i
Copyright & Disclaimer............................................................................................................................. i
Table of Contents .................................................................................................................................... ii
1.
2.
3.
ii
Pentaho
4.
5.
6.
7.
8.
9.
iii
1. PENTAHO OVERVIEW
Pentaho
Features of Pentaho
Pentaho Reporting primarily includes a Reporting Engine, a Report Designer, a Business
Intelligence (BI) Server. It comes loaded with the following features:
Report Designer and Design Studio: Used for fine-tuning of reports and ad-hoc
reporting.
Pentaho user console web interface: Used for easily managing reports and
analyzing views.
Ad-Hoc reporting interface: Offers a step-by-step wizard for designing simple
reports. Output formats include PDF, RTF, HTML, and XLS.
Connectivity: Connectivity between the reporting tools and the BI server, which
allows to publish the content directly to the BI server.
2. PENTAHO INSTALLATION
Pentaho
Let us now learn how to install and configure Pentaho Reporting Designer.
Prerequisites
The Pentaho Reporting engine requires Java environment. Therefore, before installing
Pentaho Reporting, make sure you have Java on your system. Based on the platform you
are working on, use a command from the following table to verify your Java installation.
OS
Command
Windows
Open command
prompt:
\>java -version
Linux
Open terminal:
$ java version
Mac OS
Open terminal:
$ java version
Output
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09,
mixed mode)
java version "1.7.0_60"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4x86_64) OpenJDK 64-Bit Server VM (build 60.7-b01,
mixed mode)
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09,
mixed mode)
If you do not have Java installed on your system, then download and install the same
using the following link Download and Install Java.
Windows
Linux
Mac OS
Pentaho
Installation Instructions
Extract the downloaded file prd-ce-3.7.0-stable.zip using an Unzip
tool.
Copy the extracted folder (prd-ce-3.7.0-stable) into c:\ directory.
Windows
Linux
# mv prd-ce-3.7.0-stable /usr/local/
Copy and Paste Pentaho Report Designer from Finer into /Application
folder.
Mac
$ report-designer.sh
Pentaho
3. PENTAHO NAVIGATION
Pentaho
This chapter will provide a brief introduction on the user interfaces available in Pentaho
and how to navigate through them.
Report Wizard: It provides an easy-to-use four steps process that walk you
through creating a new Report.
New Report: If you choose this option, then you can create customized reports
based on your requirement.
Pentaho has a set of sample reports to help you figure out how to use a certain Report
Designer. The following screenshot shows the welcome page of Pentaho.
Pentaho
Page Header: You can use any type of data here that is suitable to print on top of
every report page. It does not allow any dynamic values or page breaks.
Report Header: The second band from top is the Report Header. It contains the
report elements. It appears once per report, that is on the first page of the report.
Details: The Details band is the largest portion of your page because most of the
report data is presented in this area.
Report Footer: Just like the Report Header, the Report Footer appears just once
per report, that is on the last page of the report.
Page Footer: The last band is the Page Footer which appears at the absolute
bottom of every page in the report.
You can also create groups for various report elements. Each group has its own Header
and Footer bands in the workspace.
Pentaho
Pentaho
Datasources: All the data sources and queries that you have defined for the
current report will be listed here. If you want to add a new data source, then rightclick on the leftmost button (the yello cylinder) click add.
Functions: All the functions (mathematical and conditional) elements that you
added to a report will be listed in this category. You can add a function by clicking
the (fx) button.
Parameters: You can add a parameter to your report, which will enable the report
readers to customize the content of the output.
Pentaho
The Palette
The palette contains all the elements that you can use to build a report. To add an element,
click on a layout band to select it, then drag and drop an element from the palette to the
Pentaho
selected band. We have explained the role of each of the report elements in the following
table.
Element name
Description
Label
Text-Field
Number-Field
Date-Field
Message
Resource-label
Resource- Message
Image-Field
Image
Ellipse
Resource-Field
Rectangle
Horizontal-Line
Vertical-Line
Survey-Scale
Chart
Simple-Barcodes
Bar-Sparkline
Line-Sparkline
Pie-Sparkline
Band
Sub-Report
Table-Of-Content
Pentaho
Index
Take a look at the following screenshot; the highlighted box on the left side is the palette
of reporting elements.
11
In this chapter, we will learn to use the Pentaho Reporting Designer by taking an example.
We will create a report on the employee database to produce a quick overview of every
employee. We will create our first report by adding a data source and passing queries to
the Pentaho Designer.
Before using Pentaho Report Designer, create a database named employeedb and in that
database, create a table named employee using the following query.
CREATE TABLE 'employee' (
'id' integer NOT NULL,
'name' varchar(20),
'designation' varchar(20),
'department' varchar(20),
'age' integer,
PRIMARY KEY ('id'))
Insert the following records into the table.
Id
Name
Designation
Department
age
1201
'satish'
'writer'
'Tuto_Write'
24
1202
'krishna'
'writer'
'Tuto_Write'
26
1203
'prasanth'
'php developer'
'Tuto_develop'
28
1204
'khaleel'
'php developer'
'Tuto_develop'
29
1205
'raju'
'HTML developer'
'Tuto_develop'
24
1206
'javed'
'HTML developer'
'Tuto_develop'
22
1207
'kiran'
'Proof Reader'
'Tuto_Reader'
28
1208
'pravenya'
'Proof Reader'
'Tuto_Reader'
30
1209
'mukesh'
'Proof Reader'
'Tuto_Reader'
28
1210
'sai'
'writer'
'Tuto_writer'
25
1211
'sathish'
'graphics designer'
'Tuto_designer'
26
1212
'viswani'
'graphics designer'
'Tuto_designer'
24
1213
'gopal'
'manager'
'Tuto_develop'
29
1214
'omer'
'manager'
'Tuto_writer'
32
12
Pentaho
1215
'shirjeel'
'manager'
'Tuto_Reader'
32
If you want to manipulate the data contained inside the table, the best choice is to use
SQL. But if you want to create a report based on the data, Pentaho Reporting is the best
option. Our task is to pass an SQL query to the Pentaho Reporting designer tool and select
respective fields (which are presented in the report) and present it on the Details of the
report sheet.
Before moving further, make sure you are well versed with all the navigation options
available in Pentaho (explained in the previous chapter). Now that we have a data source,
let us proceed further and try to understand how to use Pentaho to generate a professional
report.
Pentaho
In the Data tab, right-click on the Data Sets and select JDBC to add a data source.
Generally, in the list of options, you can select any other option based on the requirement.
It means, if you have an XML file as your data source, then choose XML option from the
list. Take a look at the following screenshot. Here we are selecting the JDBC option to add
a database as data source.
After having selected the JDBC option as the data source, you will find a dialog box as
shown in the following screenshot.
We have already chosen MySQL database for the data source, therefore we have to select
the SampleData (MySQL) option in the left-side panel of the dialog box (marked as
pointer "1" in the given screenshot. Pointer "2" is meant for editing the connection
statement and URL to interact with the database.
14
Pentaho
The following screenshot shows a dialog box where you can define your connection
statement and the URL for the database. We need to carry out four operations on the
following screen (which are highlighted using pointers).
1. In the connection type list, select MySQL: We have already chosen MySQL as the
database (data source).
2. In the Access list, select Native (JDBC): Through JDBC connection, we can access
the database.
3. In the Settings section, we must mention the Host Name (localhost), Database
name (employeedb), port number (3306), username (root), and the password (as
per you system).
4. Test the connection statement by clicking the Test button.
Finally, click the OK button to confirm the database connection.
15
Pentaho
The Available Queries block on the right side of the dialog box displays a list of
all the available queries.
The Query Name block displays the selected query name which is selected in the
above available queries list.
The Query block displays the query statement. If no queries are available or if you
want to create a new query, click the + button which is highlighted as pointer
1 in the following screenshot.
16
Pentaho
While clicking the + button, you can create a query by editing a name on the Query
Name block as select_all_records and use the following query statement in the Query
block.
SELECT
employee.id,
employee.name,
employee.designation,
employee.department,
employee.age
FROM
employee
LIMIT
15
After adding the query, you should get the following dialogue box. Click the preview
button.
17
Pentaho
After clicking the preview button, you will find all the employee table records in a separate
dialog box as shown in the following screenshot. Click the close button.
Then, click the OK button to submit the query. After submitting the query, you will find all
the table field names and their datatypes under the query name on the right-side structure
pane, as shown in the following screenshot. Here, the maximized box is the structure pane
which is placed on the right side of the screen.
18
Pentaho
We have so far added a data source and a query to the Pentaho Reporting Designer. Now,
we have to add elements into the workspace to create a report. The same example is
extended to the next chapter "Reporting Elements".
19
Pentaho
Most reporting elements can easily be added by dragging and dropping them from the
Data pane to any of the bands on the workspace (mostly Details band).
Let us continue with the same example taken from the previous chapter. There we have
added a data source and a query to the Reporting Designer. Here we will design the report
based on the output produced by the query.
The resultant query fields are the reporting elements which are highlighted in the following
screenshot. Those are: id, name, designation, department, and age.
Now, drag the required fields (fields you want to display in the report) from the Structure
Pane into the Details Band at the center of the main workspace.
Take a look at the following screenshot. It shows the direction to drag the age field from
the structure pane.
20
Pentaho
After arranging all the fields in the Details band, you can see the report view by clicking
the view button which is pointed as 1 in the above screenshot.
After clicking the view button, the result report will be as shown in the following
screenshot. In the workspace, you will find the values of all the fields (which are specified
in the Details tab).
21
Pentaho
Now, if you want to go back to the design mode, then click the Design symbol marked as
1 in the following screenshot.
22
Pentaho
Each page of a report contains two special areas. At the top of every page, you will find
the page-header area. And at the bottom of the page, you will find the page-footer
area. The remaining page is available for the actual report content.
Then, you will find a dialog box with different functions segregated into different groups.
To print the maximum age of an employee at the page footer, we should choose the
Maximum function in the Summary group which is marked as 1 in the following
screenshot. Select it and click OK.
23
Pentaho
Once you click the Ok button, the function will be added to the Functions label in the
Structure Pane which is placed at the right side of the screen.
Once you select the added function (i.e. Maximum), you will find another pane below the
structure pane containing the properties of that function.
Take a look at the following screen. The maximized box contains two pointers (Pointer 1
and Pointer 2).
Pointer 1: Select the function in the data tab of the structure pane.
Pointer 2: Edit the Field name in the properties section by selecting the age field
from the dropdown list. It is because we have to print the maximum age of an
employee.
24
Pentaho
Now, the function is ready with the customized properties. Now you can use that function
in your report as a page footer attribute.
Take a look at the following screenshot. Again, it contains two pointers (Pointer 1 and
Pointer 2).
Pointer 1: Select and drag the Maximum function from the Structure pane to the
page footer band in the workspace, as shown in the following screenshot. Now the
design of your report is ready.
Pointer 2: Select the Preview button on the left side of the screen.
25
Pentaho
Take a look at the following screen. It shows the preview of the report. The maximum age
of an employee is marked and shown in a maximized box.
26
7. PENTAHO GROUPS
Pentaho
Pentaho offers various functionalities and features to convert raw data into meaningful
information. Here, we will learn how to use one such feature Groups. You can use this
feature to segregate raw row-set data into groups so that the user can easily understand
the report.
Grouping is a great way to divide long lists of data along meaningful separators.
With groups, you can keep similar items together and visually separate these items
from other groups of items.
You will also need groups to perform various aggregations over the data, like
printing the number of items in a group or calculating sums or averages.
You will get a list of options by clicking the Add group button. Then, click the Add Group
option from the list.
After clicking Add Group, you will find a dialogue box using which you can add a group
field from the given available fields.
27
Pentaho
Take a look at the following screenshot. The three activities are highlighted in the dialog
box which we have marked as 1, 2, and 3.
Pointer 2: Select the department field from the available fields list.
Pointer 3: Click the arrow (->) button so that the selected field gets copied to the
selected Fields list.
Select that department field in the selected fields list and click OK to confirm.
After adding the group, you will find it in the Structure tab of the Structure pane. And you
will find the Group Header and Group Footer bands in the workspace.
Take a look at the following screenshot. Add a static label to your report by dragging the
label icon from the palette on the left side of the Report Designer into the group header
(in the screenshot, this activity has been marked as 1).
By double-clicking the label, you can edit it and change the name to Department. By
using the Formatting Toolbar or the Formatting Palette (marked as "3" and "4"
respectively), you can change the format of the label.
28
Pentaho
Let us now proceed further. Switch the Structure pane to Data tab. Select and drag the
department field from the Structure pane to the Group Header (this activity is marked as
1 in the following screenshot). To see a preview of your report, click the preview button
on the left side of the screen which is highlighted and marked as 2 in the following
screenshot.
After clicking the preview button, you will find the result report as shown in the following
screenshot. You will find the records have now been grouped together according to
department.
29
Pentaho
The report does not look very appealing at this stage. You can add a touch of color and
make the heading more effective using the Formatting Toolbar or the Formatting Palette.
You are now ready to generate different types of reports using Pentaho. Just follow the
steps discussed so far and try to use all the features and options available in Pentaho.
30
Pentaho
Speed
User Rating
Mileage
Safety
Fiat
Audi
10
Ford
First of all, create a table named car based on the given table data. We are using MySQL
database as the data source. Add that (data source) to the Pentaho Reporting Designer.
We have already discussed how to add a data source and a query to the Pentaho Reporting
Designer in the chapter "Pentaho Data Sources and Queries".
Pentaho
car.millage,
car.safety
From
car
LIMIT
3
The following screenshot shows how to add the given query to the data source.
32
Pentaho
4. You have two options to insert an image. Either link the image URL to the report
or embed the image into the report. We chose to embed the image by selecting the
option Embed in Report.
5. Download some sample car image from the internet to put into the Page Header.
Click on the button to locate the sample car image with the location URL. Click the
OK button to confirm.
33
Pentaho
Marker 1 is a dropdown list where you have to select the Category Set Data
Collector.
There are three sections in the Primary Data Source: Common, Series, and Group. Here,
we dont require to add anything on the Groups section because we are not using any
Groups in our query.
Common There are two fields in this section: category-column and value-column.
We already filled the category-column value with the name field in the above section. The
second one is value-column.
Click on the empty value; you will find a dialogue box as shown in the following screenshot.
There are two activities (1 and 2) marked in it.
Click the (+) button to add the value fields in the column.
By clicking on the empty value, you will find a dropdown list from where you need
to select the speed field.
34
Pentaho
Repeat the above two activities to add user_rating, mileage, and safety fields into the
column. After adding all these fields, the screen will appear as shown below. Click OK to
confirm.
The next column in the Primary Data source section is the Series section.
Series In the Series field, click the series-by-value option. You will find a dialogue box
as shown in the following screenshot. There are two markers (1 and 2) in it.
1. Click the (+) button to add a new field in the column.
2. By double-clicking on it, you can edit that field.
Repeat these two activities for adding field names such as Speed, User Rating, Mileage,
and Safety.
35
Pentaho
These are the user-defined names to present in the particular section of report chart. But
here you have follow the same order that you have given on the Value-column fields in
the Common section. Click OK after adding all the fields as shown below.
After adding all the sections, you will get the Edit Chart dialogue box as shown in the
following screenshot. The Bar Chart pane contains different properties which are used for
changing the chart format.
In the General section of the Bar Chart, we have changed the 3-D value as true (marked
as "1"). Click OK to confirm the chart properties.
36
Pentaho
Click on the Preview button on the Formatting Toolbar to see a preview of the report. It
will appear as shown in the following screenshot:
You can implement different types of charts in your report by using different types of data
models and by providing different values to the chart properties. Pentaho provides almost
18 types of charts in the report designer.
37
Once you have placed a report element in the workspace, it can be formatted in different
ways. Pentaho Reporting Designer provides various features to format the reporting
elements as per our requirement.
Text Formatting
All the text-based elements such as text, number, date, and labels can be easily formatted
using the Formatting Toolbar that appears just above the Report Canvas.
Take a look at the following screenshot. Here, we have marked and highlighted three
objects:
1. Selected Report Element
2. Formatting toolbar
3. Style Pane tab for formatting the report elements
First of all, select the Report Element on the workspace. Thereafter, you can format that
element in many ways using the Formatting toolbar or using the properties from the Style
Tab pane.
Adding Hyperlinks
Pentaho Report Designer allows you to add hyperlinks to your report data. Here we will
take a general example to explain how to add hyperlinks in your report.
Assume that we have already added a query in the employee table to fetch the fields id,
name, and designation. We have also added these fields to the Reporting workspace. Here
38
Pentaho
our requirement is to pass the individual values of
www.google.co.in as a parameter value using a hyperlink.
the
designation
field
to
First, select the designation field in the workspace. Right click on it and select Hyperlink
from the list. Take a look at the following screenshot.
After clicking the Hyperlink option, you will find a dialog box where you have to provide
details such as Type of the hyperlink location, URL, Target, Parameter name, and Value.
Take a look at the following screenshot. Here we have marked and highlighted the
following five activities:
1. Provide the type of Hyperlink Location. Generally there are four types of locations:
Pentaho Repository - If you install Pentaho Repository, then provide that file
URL in the localhost (Login is required).
Pentaho
5. Provide a Parameter name and a value to the URL of the Hyperlink. Here we have
used q as the Parameter name and Designation field as the Parameter value.
Finally, click OK to confirm the Hyperlink properties.
Click the Preview button on the formatting toolbar to see a preview of the report. After
clicking the Preview button, you will find the following screenshot. Place the mouse pointer
on any designation value either HR or Admin to see its respective URL.
In this Pentaho Report Designer preview, the hyperlink is meant for redirecting the user
to another URL. For that, you have to run this report on HTML by clicking the Run button
on the Main toolbar (marked as "1" in the following screenshot) and select the HTML option
on it.
Take a look at the following screenshot. There are different options for running the report,
but we have chosen to display the report in HTML format.
40
Pentaho
After selecting the HTML option, you will find the report data in a separate HTML page, as
shown in the following screenshot. Click on any Designation value to understand how a
hyperlink works in Pentaho Reporting.
Row Banding
Pentaho Report Designer has a row banding property that allows you to color the alternate
rows of your report. Let us take our previous example to understand how it works.
After adding the elements into the workspace, click the report workspace -> go to the
Format menu -> select Row Banding. Take a look at the following screenshot.
41
Pentaho
After selecting the Row Banding option, you will find a dialog box. Here, you can select a
color from the dropdown list. We have selected red and green as the alternate colors. Now,
click the OK button to confirm. Take a look at the following screenshot.
Click the Preview button to see how your report appears with alternate row colors. It will
appear as shown in the following screenshot.
42
Pentaho
43
10.
PENTAHO FUNCTIONS
Pentaho
Each page of a report contains a Page-header area and a Page-footer area. The
remaining page is available for the actual report content.
The page footer tab is used to present some attributes and functions. For example, we can
print the max value of the age field of an employee in the Page-footer. The reporting
engine allows these features by using functions.
Let us use the same employee table which we have used in the previous chapters. After
adding all the fields into the report workspace, let us now add a function into the Pagefooter tab to find out the maximum age of an employee.
Follow the steps given below to add a predefined function to your report.
44
Pentaho
Once you click the Ok button, the function will be added to the Functions label in the
Structure Pane which is placed at the right side of the screen.
Pointer 1: Select the function in the data tab of the structure pane.
Pointer 2: Edit the Field name in the properties section by selecting the age field
from the dropdown list. It is because we have to print the maximum age of an
employee.
45
Pentaho
Pointer 1: Select and drag the Maximum function from the Structure pane to the
page footer band in the workspace, as shown in the following screenshot. Now the
design of your report is ready.
Pointer 2: Select the Preview button on the left side of the screen.
46
Pentaho
47
Pentaho
Function Name
Purpose
Open Formula
Page
Page of Pages
S. No.
Function Name
Purpose
Is Export Type
Row Banding
Hide Repeating
S. No.
Function Name
Sum
Purpose
Calculates the sum of the selected numeric column.
48
Pentaho
Count
Count by Page
Group Count
Minimum
Maximum
Sum Quotient
Sum Quotient
Percent
Calculation
10
Count of pages
11
Sum of Pages
S. No.
Function Name
Purpose
Sum
Count
Group Count
Count Distinct
Average
49
Pentaho
Minimum
Maximum
Percent of Total
S. No.
Function Name
Purpose
Message Format
Resource
Message Format
Lookup
Indirect Lookup
Resource Bundle
Lookup
Open Formula
50