bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Working with Databases

 

Creating a connection with the Steel Wheels database:

  1. Go to the Pentaho Download site: http://sourceforge.net/projects/pentaho/files/.
  2. Under the Business Intelligence Server look for the file named pentaho_sample_data-1.7.1.zip and download it.
  3. Unzip the downloaded file.
  4. Run start_hypersonic.bat under Windows or start_hypersonic.sh under Unix-based operating systems. If you download the sample data, you will find these scripts in the folder named pentaho-data. If you download the Pentaho BI server instead, you will find them in the folder named data. The following screen is displayed when the database server starts:

1

  1. Open Spoon and create a new transformation.
  2. Click on the View option that appears in the upper-left corner of the screen.
  3. Right-click the Database connections option and click on New.

1

8. Fill the Database Connection dialog window.

1

  1. Click on the Test button. The following window shows up:

110. Click on OK to close the test window.

11. Click on OK again to close the database definition window. A new database connection is added to the tree.

12. Right-click on the database connection and click on Share. The connection is available in all transformations you create from now onwards.

1

  1. Save the transformation.

Exploring the sample database:

  1. Open the transformation you just created.
  2. Right-click the connection in the Database connections list and select Explore in the contextual menu. The Database explorer on connection window opens.
  3. Expand the Tables node of the tree and select CUSTOMERS. This is how the explorer looks:

1

  1. Click on the Open SQL for [CUSTOMERS] option.
  2. The following SQL editor window appears:

1

  1. Modify the text in the window so that you have the following:
SELECT

CUSTOMERNUMBER

, CUSTOMERNAME

, CITY

, COUNTRY

FROM CUSTOMERS
  1. Click on Execute. You will see the following result:

1

  1. Close the preview window (the window that tells the result of the execution) and the SQL editor window.
  2. Click on OK to close the database explorer window.

A brief word about SQL:

SQL, that is, Structured Query Language is the language that lets you access and manipulate databases in a RDBMS.

SQL can be divided into two parts—DDL and DML.

The DDL, that is, Data Definition Language is the branch of the language that basically allows creating or deleting databases and tables.

DML, that is, Data Manipulation Language allows you to retrieve data from a database. It also lets you insert, update, or delete data from the database.

The statement you typed in the SQL editor is an example of DML:

SELECT

CUSTOMERNUMBER

, CUSTOMERNAME

, CITY

, COUNTRY

FROM CUSTOMERS

Getting orders in a range of dates by using parameters:

  1. Open the transformation from the previous tutorial and save it under a new name.
  2. From the Input category, add a Get System Info step.
  3. Double-click it and use the step to get the command line argument 1 and command line argument 2 values. Name the fields as date_from and date_to respectively. Create a hop from the Get System Info step to the Table input step.
  4. Double-click the Table input step.
  5. Modify the SELECT statement as follows:
SELECT

ORDERNUMBER

, ORDERDATE

, REQUIREDDATE

, SHIPPEDDATE

FROM ORDERS

WHERE STATUS = 'Shipped'

AND ORDERDATE BETWEEN ? AND ?
  1. In the drop-down list to the right side of Insert data from step, select the incoming step.
  2. Click OK.
  3. With the Select values step selected, click the Preview button
  4. Click on Configure.
  5. Fill the Arguments grid. To the right of the argument 01, type 2004-12-01. To the right of the argument 02, type 2004-12-10.
  6. Click OK. The following window appears:

1

Getting orders in a range of dates by using variables:

  1. Open the main transformation we created in the Time for action–getting data about shipped orders section and save it under a new name.
  2. Double-click the Table input step.
  3. Modify the SELECT statement as follows:
SELECT

ORDERNUMBER

, ORDERDATE

, REQUIREDDATE

, SHIPPEDDATE

FROM ORDERS

WHERE STATUS = 'Shipped'

AND ORDERDATE BETWEEN ‘${DATE_FROM}’ AND ‘${DATE_TO}’

  1. Tick the Replace variables in script? checkbox.
  2. Save the transformation.
  3. With the Select values step selected, click the Preview button.
  4. Click on Configure.
  5. Fill the Variables grid in the settings dialog window—type 2004-12-01 to the right of the DATE_FROM option and 2004-12-10 to the right of the DATE_TO option.
  6. Click OK. This following window appears:

1

Deleting data about discontinued items:

  1. From the Packt website, download the LUX_discontinued.txt file.
  2. Create a new transformation.
  3. With a Text file input step, read the file.
  4. Preview the file.

1

  1. After the Text file input step, add an Add constants step to add a String constant named man_code with value LUX.
  2. Expand the Output category of steps and drag a Delete step to the canvas.
  3. Create a hop from the Add constants step to the Delete step.
  4. Double-click the Delete step. Select js as Connection and, as Target table, browse and select products. In the grid add the conditions man_code = man_code and pro_theme LIKE category. After the Delete step, add a Write to log step.
  5. Right-click the Delete step and define the error handling.
  6. Save the transformation.
  7. Before running the transformation, open the Database Explorer.
  8. Under the js connection, locate the products table and click Open SQL for .
  9. In the simple SQL editor type:

SELECT pro_theme, pro_name FROM js.products p

ORDER BY pro_theme, pro_name;

  1. Click on Execute.

1

  1. Close the preview data window and the results of the SQL window.
  2. Minimize the database explorer window.
  3. The database explorer is collapsed at the bottom of the Spoon window.
  4. Run the transformation.
  5. Look at the Step Metrics. The following is what you should see:

1

  1. Maximize the database explorer window.
  2. In the SQL editor window click Execute again.

1

"0 Responses on Working with Databases"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Working with Databases.