Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{scrollbar}
{

Excerpt

...

How

...

to

...

create

...

a

...

parameterize

...

report

...

that

...

uses

...

data

...

from

...

a

...

collection

...

in

...

MongoDB.

...

By

...

the

...

end

...

of

...

this

...

guide

...

you

...

should

...

understand

...

how

...

data

...

can

...

be

...

read

...

from

...

MongoDB

...

and

...

used

...

in

...

a

...

report.

...

The

...

data

...

we

...

are

...

going

...

to

...

use

...

contains

...

data

...

about

...

the

...

flow

...

of

...

visitors

...

to

...

a

...

web

...

site.

...

This

...

guide

...

shows

...

how

...

to

...

create

...

a

...

report

...

that

...

shows

...

the

...

most

...

popular

...

landing

...

pages

...

for

...

the

...

sample

...

web

...

site.

...

Intro

...

Video

Prerequisites

In order follow along with this how-to

...

guide

...

you

...

will

...

need

...

the

...

following:

...

MongoDB

...

A

...

single-node

...

local

...

cluster

...

is

...

sufficient

...

for

...

these

...

exercises

...

but

...

a

...

larger

...

and/or

...

remote

...

configuration

...

will

...

work

...

as

...

well.

...

You

...

will

...

need

...

to

...

know

...

the

...

address

...

and

...

port

...

that

...

MongoDB

...

is

...

running

...

on

...

and

...

have

...

a

...

user

...

id

...

and

...

password

...

for

...

the

...

server

...

(if

...

applicable).

...


These

...

guides

...

were

...

developed

...

using

...

the

...

MongoDB

...

version

...

2.0.2.

...

You

...

can

...

find

...

MongoDB

...

downloads

...

here:

...

http://www.mongodb.org/downloads

...

Kettle

A desktop installation of the Kettle design tool called 'Spoon'.

...

Download

...

here.

...

Pentaho Report Designer

Pentaho Report Designer (PRD)

...

is

...

a

...

desktop

...

tool

...

for

...

creating

...

highly

...

formatted

...

reports

...

that

...

can

...

be

...

exported

...

to

...

many

...

popular

...

formats.

...

Reports

...

created

...

with

...

PRD

...

can

...

be

...

published

...

to

...

a

...

Pentaho

...

BI

...

Server

...

so

...

they

...

can

...

be

...

accessed

...

using

...

a

...

browser.

...

Download

...

here.

...

Data

To follow this guide you need to have a populated MongoDB collection. If you do not have any data in MongoDB yet you can use the Write Data To MongoDB guide to add some data to your MongoDB installation. You will also need the transformation created in Create a Report with MongoDB. The instructions in this guide assume that the demo data set is available in a collection called PageSuccessions in a database called Demo and that you have access to the transform called 'top_landing_pages.ktr'.

...

Step-By-Step

...

Instructions

...

We

...

will

...

create

...

the

...

report

...

using

...

two

...

tools.

...

First

...

we

...

will

...

use

...

Spoon

...

to

...

modify

...

the

...

data

...

transformation

...

that

...

selects

...

data

...

from

...

MongoDB

...

and

...

sorts

...

it

...

into

...

descending

...

order.

...

Then

...

we

...

will

...

use

...

PRD

...

to

...

create

...

a

...

report

...

using

...

the

...

data

...

transformation

...

as

...

its

...

data

...

source.

...

Setup

...

Start

...

MongoDB

...

if

...

is

...

not

...

running.

...

Modify

...

the

...

Data

...

Transformation

...

Start

...

Spoon

...

on

...

your

...

desktop.

...

  1. Open the Transformation: Choose 'File'

...

  1. ->

...

  1. 'Open'

...

  1. from

...

  1. the

...

  1. menu

...

  1. system.

...

  1. Select

...

  1. the

...

  1. 'top_landing_pages.ktr'

...

  1. file.
    Image Added
  2. Edit the MongoDb Input Step: Double-click

...

  1. on

...

  1. the

...

  1. 'MongoDb

...

  1. Input'

...

  1. step

...

  1. to

...

  1. edit

...

  1. its

...

  1. properties.

...

  1. Enter

...

  1. this

...

  1. information:

...

    1. Host

...

    1. name,

...

    1. Port,

...

    1. Authentication

...

    1. user

...

    1. and

...

    1. password:

...

    1. the

...

    1. connection

...

    1. information

...

    1. for

...

    1. your

...

    1. MongoDB

...

    1. installation.

...

    1. Database:

...

    1. 'Demo'

...

    1. or

...

    1. another

...

    1. database

...

    1. if

...

    1. you

...

    1. want.

...

    1. Collection:

...

    1. 'PageSuccessions'

...

    1. Query

...

    1. expression:

...

    1. {

...

    1. "$query"

...

    1. :

...

    1. {

...

    1. "url"

...

    1. :

...

    1. "$

...

    1. {page

...

    1. }"

...

    1. },

...

    1. "$orderby"

...

    1. :

...

    1. {

...

    1. "Count"

...

    1. :

...

    1. -1

...

    1. }

...

    1. }

...


    1. The

...

    1. $

...

    1. {

...

    1. }

...

    1. syntax

...

    1. is

...

    1. used

...

    1. to

...

    1. specify

...

    1. that

...

    1. a

...

    1. parameter

...

    1. should

...

    1. be

...

    1. inserted.

...

    1. In

...

    1. this

...

    1. case

...

    1. the

...

    1. parameter

...

    1. is

...

    1. called

...

    1. "page".

...


    1. The

...

    1. window

...

    1. should

...

    1. look

...

    1. like

...

    1. this:
      Image Added
  1. Define the Transformation Parameter: In order the for parameter in the JSON query to work we need to define the parameter at the transformation level. Choose 'Edit' -> 'Settings...'

...

  1. from

...

  1. the

...

  1. menu

...

  1. system.

...

  1. Click

...

  1. on

...

  1. the

...

  1. 'Parameters'

...

  1. tab.

...

  1. Enter

...

  1. 'page'

...

  1. for

...

  1. the

...

  1. parameter

...

  1. and

...

  1. '—firstpage—'

...

  1. for

...

  1. the

...

  1. default

...

  1. value.
    Image Added
  2. Preview the Data: With the 'Json Input' step selected click on the Preview toolbar button (the green arrow with the magnifying glass Image Added ) or right-click on the step and choose 'Preview'. The 'Transformation debug dialog' will open. Click on 'Quick Launch'. You will should see the data returned by the MongoDB query with the extracted fields.
    Image Added
  3. Change the parameter value: Now we will preview the step with a different parameter. Open the 'Transformation debug dialog' window again. Click on 'Configure', the 'Execute a transformation' window will open. In the parameters section enter '/about' for the value of the page parameter.
    Image Added
    Click on the 'Launch' button.
    Image Added
    The data displayed is now for the '/about' url, . Try parameter values of '/demo' or '/events' to see how the data changes.
  4. Save the Transformation: Choose 'File' -> 'Save as...' from the menu system. Save the transformation as 'page_successions' into a folder of your choice.

Start Pentaho Report Designer

When PRD starts click on the 'Report Wizard' button or choose 'File' -> 'Report Wizard...' from the menu.

  1. Select a Template: On the 'Look and Feel' stage of the wizard select a report template and click on 'Next'
  2. Add a Data Source: On the 'Data Source' stage click on the '+' icon in the top right to add a new data source.
  3. Choose the Data Source Type: From the 'Choose Type' list click on 'Pentaho Data Integration'.
    Image Added
  4. Add a Query: In the 'Pentaho Data Integration Data Source' window click on the '+' icon to add a new query. A default query, called 'Query 1' is added. Change the name of the query to 'Top Landing Pages'. Then click on the 'Browse' button and select the 'page_successions.ktr' file created above. Finally select the 'Json Input' step.
    Image Added
    If you want you can click the 'Preview' button to see the data generated by the 'Json Input' step. Click on 'OK' to close the 'Pentaho Data Integration Data Source' window.
  5. Select the Query: In the 'Report Design Wizard' click on the 'Top Landing Pages' query to select it and then click on the 'Next' button.
  6. Layout the Fields: In the 'Layout Step' of the wizard click on 'URL' and then click the button to add 'URL' to the 'Group Items By' box. Add 'NextURL' and 'Count' to the 'Selected Items' box. This will position these two fields as two columns in the report.
    Image Added
    Click on the 'Next' button.
  7. Format the Fields: In this step you can change the formatting of the fields. Click on the 'URL' field to highlight it, then change the 'Group Header Label' to 'Source Page: '. Click on the 'NextURL' field to highlight it, then change the Display Name to 'Destination Page'. Click on 'Count' to highlight it, then change the data format to '#,###;(#,###)'

...

  1. and

...

  1. select

...

  1. 'Sum'

...

  1. from

...

  1. the

...

  1. 'Aggregation'

...

  1. list.
    Image Added
  2. Finish the Wizard: Click on 'Finish'.

...

  1. The

...

  1. wizard

...

  1. will

...

  1. close

...

  1. and

...

  1. you

...

  1. will

...

  1. see

...

  1. your

...

  1. report

...

  1. in

...

  1. design

...

  1. mode.
    Image Added
  2. Change the Titles: Double-click

...

  1. on

...

  1. the

...

  1. report

...

  1. title

...

  1. and

...

  1. change

...

  1. it

...

  1. to

...

  1. 'Pages

...

  1. Successions'.

...

  1. Double-click

...

  1. on

...

  1. the

...

  1. first

...

  1. subtitle

...

  1. and

...

  1. change

...

  1. it

...

  1. to

...

  1. 'In

...

  1. descending

...

  1. order'.

...

  1. Double-click

...

  1. on

...

  1. the

...

  1. second

...

  1. subtitle

...

  1. and

...

  1. remove

...

  1. the

...

  1. text.

...

  1. Notice

...

  1. that

...

  1. there

...

  1. are

...

  1. lot

...

  1. of

...

  1. style

...

  1. properties

...

  1. you

...

  1. can

...

  1. set

...

  1. for

...

  1. these

...

  1. report

...

  1. elements.

...

  1. Add

...

  1. a

...

  1. Parameter

...

  1. Data

...

  1. Source

...

  1. :

...

  1. Next,

...

  1. we

...

  1. need

...

  1. to

...

  1. create

...

  1. a

...

  1. data

...

  1. source

...

  1. that

...

  1. will

...

  1. be

...

  1. used

...

  1. to

...

  1. populate

...

  1. a

...

  1. UI

...

  1. control

...

  1. so

...

  1. that

...

  1. users

...

  1. can

...

  1. select

...

  1. a

...

  1. valid

...

  1. value

...

  1. for

...

  1. the

...

  1. report's

...

  1. parameter.

...

  1. On

...

  1. the

...

  1. right

...

  1. panel

...

  1. click

...

  1. on

...

  1. the

...

  1. 'Data'

...

  1. tab.

...

  1. Click

...

  1. on

...

  1. the

...

  1. 'Add

...

  1. Datasources'

...

  1. toolbar

...

  1. button

...

  1. and

...

  1. choose

...

  1. the

...

  1. 'XML'

...

  1. option.
    Image Added
  2. Define the Parameter XML Data Source: In the 'XML Data Source Editor' window click on the 'Browse' button and select the 'pages.xml' file. Click on the green '+' button to add a new Available Query. For the 'Query Name' enter 'PageList'. For the 'Query' enter '/pages/page'.

...


  1. Image Added
    Click on the 'Preview...'

...

  1. button

...

  1. and

...

  1. you

...

  1. will

...

  1. see

...

  1. the

...

  1. values

...

  1. read

...

  1. from

...

  1. the

...

  1. 'pages.xml

...

  1. '

...

  1. file.

...

  1. Add

...

  1. a

...

  1. Parameter

...

  1. :

...

  1. Next

...

  1. we

...

  1. will

...

  1. create

...

  1. a

...

  1. report

...

  1. parameter

...

  1. and

...

  1. UI

...

  1. control.

...

  1. On

...

  1. the

...

  1. data

...

  1. tab

...

  1. click

...

  1. on

...

  1. the

...

  1. 'Add

...

  1. a

...

  1. new

...

  1. Master-report

...

  1. Parameter'

...

  1. toolbar

...

  1. button

...

  1. Image Added . The 'Add Parameter...'

...

  1. window

...

  1. opens.

...

  1. Double-click

...

  1. on

...

  1. the

...

  1. 'XML'

...

  1. DataSource

...

  1. folder

...

  1. to

...

  1. open

...

  1. it,

...

  1. then

...

  1. click

...

  1. on

...

  1. the

...

  1. 'PageList'.

...

  1. Fill

...

  1. in

...

  1. these

...

  1. fields:

...

    1. Name:

...

    1. 'Page'

...

    1. Label:

...

    1. 'Page'

...

    1. Value

...

    1. Type:

...

    1. 'String'

...

    1. Display

...

    1. Type:

...

    1. 'Drop

...

    1. Down'

...

    1. Query:

...

    1. 'PageList'

...

    1. Value

...

    1. and

...

    1. Display

...

    1. Name:

...

    1. 'url'

...


    1. Image Added
  1. Connect the Parameter: Finally we need to associate the report parameter with the transformation parameter. On the right panel, double-click on the 'Page Successions' data source to edit it. Click on the 'Edit Parameter' button, the 'Transformation Parameters' window will open. Click on the green + button to add a row to the table. For 'DataRow Column' choose 'Page' from the dropdown list. For 'Transformation Parameter' choose 'page' from the dropdown list.
    Image Added
    Click on the 'OK' button to close the 'Transformation Parameters' window and then click on the 'OK' button in the 'Pentaho Data Integration Data Source' window.
  2. Preview the Report: Click on the preview icon (the eye towards the top left) to preview your report. Notice that there is a dropdown list above the report. You can use this control to change the parameter for the report. You can alter the size of the parameter panel using the grab bar between it.
    Image Added
  3. Run or Export the Report: Click on the run button (green arrow on the toolbar) or choose 'File' -> 'Export' from the menu system. Select the output format for your report. If you used the run button the report will run and the appropriate application will be opened to view the report. If you chose the export option you will be prompted for the location and name of the file that will be exported. With either method you will be given the opportunity to select the parameter value before the report runs.

Check The Results

  1. Using the run or export options you will be able to create and view PDF, Excel, HTML, and other file types. Try these options and check that the exported files contain the expected data.

Summary

During this guide you learned how to read data from a MongoDB collection and use it as the data source for a parameterized report.
Other guides in this series cover to sort and group MongoDB data, and combine data from MongoDB with data from other sources.

Wiki Markup
{scrollbar}