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

...

Excerpt

May 25, 2006
Submitted by James Dixon, Pentaho Chief Geek

This technical tip shows how to configure Kettle so that input files such as XML, CSV and Excel files can be loaded from a Pentaho solution folder.

This is useful for defining transformations that accept one or more input files that will be executed on a server without having to replicate the exact directory structure of the server in order to test your transformations.

We will load a simple XML file that has CD collection data in it, then use an action sequence to display the data in a browser. Not entirely real world complex, but it takes you through the steps so you can use your real data later on.

Resources Before You Get Started

As always, you will want to gather the  necessary resources before you start the hands on part of this article. This article's tip will NOT work with PCI (the Pentaho demo) versions PRIOR to release milestone 1.1.6.   

  • Pentaho Pre-Configured Install, version 1.1.6 build 279 or later
  • Pentaho Getting Started Guide, version 1.1.6 build 279 or later
  • Kettle, version 2.2.2 or later
  • Our sample XML file, the CD collection (cdcollection.xml) - you can download that file here.  Use your browser's right-click | Save As... option to right-click on the link and save the this file to your hard drive in a spot you will remember.
    In order to keep this tip short and to the point, I'll assume you have a working knowledge of Kettle. It is an intuitive application to use, so if you are not familiar with it, you can get up to speed rather quickly.

We need to accomplish a few different tasks to complete this exercise. First, we must configure Kettle's Spoon, and build our transformation that loads our external file. Then we need to build the action sequence that will execute the transformation. Last, we should test our solution to be sure it's all working as we expect it.

Step-By-Step: How to Build Your Transformation

Edit Spoon's Configuration
  1. If you haven't yet installed Kettle, do so now. You can find very simple installation instructions here.
  2. You should have the Pentaho sample solution available on your computer. The sample solution comes bundled in the Pentaho Pre-Configured Install (herein referred to as PCI). If you haven't yet, unzip the PCI to a location on your computer that you will remember. You can use the Getting Started Guide if you need help getting the PCI up and running.
  3. WINDOWS USERS:
    1. BEFORE you run any of Kettle applications, open the Spoon.bat file (located in the root of the Kettle install) with your favorite text editor.
    2. Find the line that reads:
      set OPT=-Xmx256m -cp %CLASSPATH% -Djava.library.path=libswt\win32

...

    1. \ -DKETTLE_REPOSITORY="%KETTLE_REPOSITORY%"

...

    1. -DKETTLE_USER="%KETTLE_USER%"

...

    1. -DKETTLE_PASSWORD="%KETTLE_PASSWORD%"

...

    1. ADD

...

    1. to

...

    1. that

...

    1. line:

...

    1.  -Dpentaho.solutionpath=

...

    1. [path

...

    1. to

...

    1. the

...

    1. root

...

    1. of

...

    1. your

...

    1. solution

...

    1. ]

...

    1. The

...

    1. solution

...

    1. path

...

    1. will

...

    1. be

...

    1. the

...

    1. path

...

    1. to

...

    1. the

...

    1. pentaho-solutions

...

    1. directory

...

    1. in

...

    1. your

...

    1. PCI.

...

    1. For

...

    1. example,

...

    1. if

...

    1. your

...

    1. PCI

...

    1. is

...

    1. installed

...

    1. to

...

    1. d:\pentaho-demo,

...

    1. then

...

    1. your

...

    1. solution

...

    1. path

...

    1. is

...

    1. d:\pentaho-demo\pentaho-solutions\.

...

    1. Make

...

    1. sure

...

    1. that

...

    1. your

...

    1. solution

...

    1. path

...

    1. ends

...

    1. with

...

    1. a

...

    1. "\"

...

    1. !

...

  1. UNIX

...

  1. and

...

  1. OS X USERS:
    1. BEFORE you run any of Kettle applications, open the Spoon.sh file (located in the root of the Kettle install) with your favorite text editor.
    2. Find the line that reads:
      OPT="-Xmx256m

...

    1. -cp

...

    1. $CLASSPATH

...

    1. -Djava.library.path=$LIBPATH"

...

    1. ADD

...

    1. to

...

    1. that

...

    1. line:

...

    1.  -Dpentaho.solutionpath=

...

    1. [path

...

    1. to

...

    1. the

...

    1. root

...

    1. of

...

    1. your

...

    1. solution

...

    1. ]

...

    1. The

...

    1. solution

...

    1. path

...

    1. will

...

    1. be

...

    1. the

...

    1. path

...

    1. to

...

    1. the

...

    1. pentaho-solutions

...

    1. directory

...

    1. in

...

    1. your

...

    1. PCI.

...

    1. For

...

    1. example,

...

    1. if

...

    1. your

...

    1. PCI

...

    1. is

...

    1. installed

...

    1. to

...

    1. /usr/joe/pentaho-demo,

...

    1. then

...

    1. your

...

    1. solution

...

    1. path

...

    1. is

...

    1. /usr/joe/pentaho-demo/pentaho-solutions/.

...

    1. Make

...

    1. sure

...

    1. that

...

    1. your

...

    1. solution

...

    1. path

...

    1. ends

...

    1. with

...

    1. a

...

    1. "/"

...

    1. !

...

  1. Save

...

  1. and

...

  1. close

...

  1. the

...

  1. configuration

...

  1. file

...

  1. that

...

  1. you

...

  1. just

...

  1. edited.

...

Create

...

Your

...

Transformation

...

  1. Copy

...

  1. the

...

  1. cdcollection.xml

...

  1. file

...

  1. to

...

  1. the

...

  1. following

...

  1. directory

...

  1. under

...

  1. your

...

  1. PCI's

...

  1. solution

...

  1. folders:

...

  1. <pentaho-demo>/pentaho-solutions/samples/etl/cdcollection.xml.

...

  1. Launch

...

  1. Kettle's

...

  1. Spoon

...

  1. application

...

  1. using

...

  1. the

...

  1. spoon.bat

...

  1. (Windows

...

  1. users)

...

  1. or

...

  1. the

...

  1. spoon.sh

...

  1. (*nix

...

  1. users)

...

  1. file

...

  1. in

...

  1. the

...

  1. root

...

  1. of

...

  1. the

...

  1. Kettle

...

  1. installation.

...

  1. In

...

  1. the

...

  1. tree

...

  1. on

...

  1. the

...

  1. left

...

  1. pane,

...

  1. locate

...

  1. the

...

  1. XML

...

  1. Input

...

  1. step

...

  1. under

...

  1. Base step types | Input.  Drag an XML Input step from the tree in the left pane to the right working pane.
  2. Double-click on the XML Input step in the right working pane to bring up the XML Input step properties dialog.
  3. Click the Browse button to locate the cdcollection.xml file in the Pentaho solution folders. Once you have selected the file, you will see the path to it in the File textbox.
  4. Next, we want to substitute the path to the root of the solutions folders with the environment variable pentaho.solutionpath, so when we move this solution to another server (likely in a real world scenario), the path to the data file remains relative to the solution and won't need to be changed.  To do this, click on the Variable button.  From the popup list, select pentaho.solutionpath. Notice that %%pentaho.solutionpath%% (${pentaho.solutionpath}

...

  1. in

...

  1. *nix)

...

  1. has

...

  1. been

...

  1. prepended

...

  1. to

...

  1. the

...

  1. path

...

  1. to

...

  1. the

...

  1. xml

...

  1. file.

...

  1. Now

...

  1. change

...

  1. the

...

  1. path

...

  1. to

...

  1. the

...

  1. xml

...

  1. file

...

  1. so

...

  1. that

...

  1. the

...

  1. %%pentaho.solutionpath%%

...

  1. replaces

...

  1. the

...

  1. root

...

  1. portion

...

  1. of

...

  1. the

...

  1. path

...

  1. to

...

  1. the

...

  1. solution

...

  1. files,

...

  1. and

...

  1. change

...

  1. all

...

  1. backslashes

...

  1. to

...

  1. forward

...

  1. slashes.

...

  1. In

...

  1. our

...

  1. example,

...

  1. the

...

  1. new

...

  1. path

...

  1. would

...

  1. look

...

  1. like

...

  1. this:
    Code Block
    
    

...

  1. %%pentaho.solutionpath%%samples/etl/cdcollection.xml
    

...

  1. We

...

  1. change

...

  1. the

...

  1. slashes

...

  1. because

...

  1. it

...

  1. is

...

  1. safest

...

  1. to

...

  1. use

...

  1. '/'

...

  1. as

...

  1. the

...

  1. file

...

  1. path

...

  1. separator

...

  1. as

...

  1. this

...

  1. text

...

  1. is

...

  1. used

...

  1. by

...

  1. Spoon

...

  1. and

...

  1. the

...

  1. Pentaho

...

  1. server

...

  1. and

...

  1. it

...

  1. will

...

  1. work

...

  1. equally

...

  1. well

...

  1. on

...

  1. Windows

...

  1. and

...

  1. Linux

...

  1. and

...

  1. OS

...

  1. X,

...

  1. whereas

...

  1. '\'

...

  1. will

...

  1. only

...

  1. work

...

  1. on

...

  1. Windows.

...

  1. Click

...

  1. the

...

  1. Add

...

  1. button

...

  1. to

...

  1. add

...

  1. the

...

  1. path

...

  1. to

...

  1. your

...

  1. xml

...

  1. file

...

  1. to

...

  1. the

...

  1. Selected

...

  1. Files

...

  1. list.

...



  1. Image Added
  2. Switch to the Content tab. Here we want to specify the location of the node in the xml file that represents the repeating data that will become rows of data in our resultset. In the cdcollection.xml file the cd node under the catalog node is the location that represents our repeating data. In the Location list, add the catalog element first, then add the cd element second.

    Image Added
  3. Switch to the Fields tab. Click the Get Fields button. If all has gone well, you should see the Field list populated with 4 fields - Title1, Artist1, Price1 and Category1.
  4. Click the Preview Rows button. Your transformation is working successfully if you get a popup dialog filled with the CD collection data. If you don't, go back and carefully verify each step again.
  5. Click OK to close the properties dialog.
  6. Finally, we want to export your new transformation to your Pentaho solutions folders. From the File menu, choose the Export to XML option, and save your transformation as cdcollection_transform.xml in the <pentaho-demo>/pentaho-solutions/samples/etl

...

  1. directory.

...

  1.  

Step-By-Step:

...

How

...

to

...

Build

...

Your

...

Solution

...

  1. To

...

  1. finish

...

  1. this

...

  1. thing

...

  1. up,

...

  1. we

...

  1. will

...

  1. reuse

...

  1. the

...

  1. sample

...

  1. etl

...

  1. action

...

  1. sequence

...

  1. that

...

  1. comes

...

  1. with

...

  1. the

...

  1. PCI.

...

  1. Make

...

  1. a

...

  1. copy

...

  1. of

...

  1. the

...

  1. SampleTransformation.xaction

...

  1. file

...

  1. and

...

  1. name

...

  1. that

...

  1. copy

...

  1. xml_input.xaction.

...

  1. You

...

  1. can

...

  1. find

...

  1. the

...

  1. SampleTransformation.xaction

...

  1. file

...

  1. in

...

  1. <pentaho-demo>/pentaho-solutions/sampes/etl

...

  1. directory.

...

  1. Make

...

  1. a

...

  1. copy

...

  1. of

...

  1. the

...

  1. SampleTransformation.properties

...

  1. file

...

  1. and

...

  1. name

...

  1. that

...

  1. copy

...

  1. xml_input.properties.

...

  1. You

...

  1. can

...

  1. find

...

  1. the

...

  1. SampleTransformation.properties

...

  1. file

...

  1. in

...

  1. <pentaho-demo>/pentaho-solutions/sampes/etl

...

  1. directory.

...

  1. Open

...

  1. the

...

  1. xml_input.properties

...

  1. file

...

  1. in

...

  1. your

...

  1. favorite

...

  1. text

...

  1. editor.

...

  1. At

...

  1. the

...

  1. top

...

  1. of

...

  1. the

...

  1. file,

...

  1. change

...

  1. the

...

  1. value

...

  1. of

...

  1. the

...

  1. <name>

...

  1. node

...

  1. to

...

  1. be

...

  1. xml_input.xaction.

...

  1. It

...

  1. should

...

  1. look

...

  1. like

...

  1. this:
    Code Block
    
    

...

  1. <name>xml_input.xaction</name>
    

...

  1. Under the resources/transformation-file/solution-file

...

  1. nodes,

...

  1. change

...

  1. the

...

  1. value

...

  1. of

...

  1. the

...

  1. location

...

  1. node

...

  1. to

...

  1. cdcollection_transform.xml.

...

  1. It

...

  1. should

...

  1. look

...

  1. like

...

  1. this:

...

  1. Code Block
    
    <location>cdcollection_transform.xml</location>
    

...

  1. Under

...

  1. the

...

  1. component-definition

...

  1. node,

...

  1. change

...

  1. the

...

  1. value

...

  1. of

...

  1. the

...

  1. importstep

...

  1. node

...

  1. to

...

  1. "XML

...

  1. Input",

...

  1. without

...

  1. the

...

  1. quotes.

...

  1. This

...

  1. is

...

  1. the

...

  1. name of the step we created in our transformation. If you changed the step name in the transformation, then also change it here.  It should look similar to this:
Code Block

<importstep>XML Input</importstep>
# 
  1. Save

...

  1. and

...

  1. close

...

  1. the

...

  1. xml_input.xaction

...

  1. file.

...

  1. Open

...

  1. the

...

  1. xml_input.properties

...

  1. file

...

  1. in

...

  1. your

...

  1. favorite

...

  1. text

...

  1. editor.

...

  1. Change

...

  1. the

...

  1. value

...

  1. of

...

  1. the

...

  1. title

...

  1. property

...

  1. to

...

  1. "2.

...

  1. XML

...

  1. Input

...

  1. Example",

...

  1. without

...

  1. the

...

  1. quotes.

...

  1. Change

...

  1. the

...

  1. value of  the description property to "How to configure Kettle so that input files such as XML, CSV and Excel files can be loaded from a Pentaho solution folder.", without the quotes.
  2. Save and close the xml_input.properties

...

  1. file.

...

  1.  

Step-By-Step:

...

How

...

to

...

Test

...

Your

...

Solution

...

Follow

...

the

...

steps

...

given

...

to

...

test

...

out

...

your

...

new

...

solution

...

in

...

the

...

server.

...

  1. First,

...

  1. make

...

  1. sure

...

  1. your

...

  1. PCI

...

  1. is

...

  1. up

...

  1. and

...

  1. running.

...

  1. If

...

  1. you

...

  1. don't

...

  1. know

...

  1. how

...

  1. to

...

  1. get

...

  1. it

...

  1. started,

...

  1. or

...

  1. are

...

  1. unsure

...

  1. as

...

  1. to

...

  1. whether

...

  1. it's

...

  1. already

...

  1. running,

...

  1. see

...

  1. the

...

  1. Pentaho

...

  1. Getting

...

  1. Started

...

  1. Guide

...

  1. for

...

  1. how

...

  1. to

...

  1. successfully

...

  1. start

...

  1. the

...

  1. server.

...

  1. Next

...

  1. make

...

  1. sure

...

  1. that

...

  1. the

...

  1. solution

...

  1. folders

...

  1. you

...

  1. are

...

  1. using

...

  1. in the PCI contains your xml_input.xaction

...

  1. !

...

  1. Navigate through the sample pages to the ETL samples. From the Samples home page, go to "A Collection of Samples and Examples" | "Extraction, Transformation and Loading with Kettle".
  2. You should see the link to your new action sequence, labeled "XML Input Example". If you don't, try refreshing your solution repository by navigating to Content and Settings, and clicking the Publish link for the Solution Repository.
  3. Click the "XML Input Example" link. You should see your CD collection data in a new browser window.

    Image Added

Our example deployment of this solution is just one way you could deploy it. You can execute this action sequence in this PCI or any other Pentaho server using the web service, Java API or user interface. The Pentaho server automatically sets the 'pentaho.solutionpath', so no configuration is necessary on the server. 

Please feel free to comment on this article.

best regards,
Gretchen