Creating OLAP document using SpagoBI and Oracle 11g database....
SpagoBI, ORACLE and OLAP
Stephen Ogutu www.ogutu.org
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Copyright © 2013 by Stephen Ogutu All rights reserved, including the right to reproduce this book or portions thereof in any form whatsoever. For information, address: Stephen Ogutu, P.O. Box 8031-00200 Nairobi Kenya
.
Trademarks: All other trademarks are the property of their respective owners. Stephen Ogutu is not associated with any product or vendor mentioned in this book. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties or merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss or profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.
1
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Dedication This book is dedicated to the memory of my late mother, a great woman. My beautiful wife Sheila for her unending support and my two cute children Emmanuel and Shallin.
Acknowledgments Special thanks to the SpagoBI community and the ow2 consortium. Thank you all for creating a great product and documenting it effectively.
2
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Contents Introduction. ................................................................................................................................................. 5 Introduction to Oracle. ................................................................................................................................. 6 Oracle express download Steps. ............................................................................................................... 6 Oracle SQL Developer. ............................................................................................................................ 10 OLAP with JPIVOT ................................................................................................................................ 16
3
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
4
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Introduction. Oracle is the most used production database in the world with a market share of more than 40% as at 2013. It is probable that this is the database that you will be using with your SpagoBI projects so we thought it useful to dedicate this small book to one task only, show you how to create an OLAP document using SpagoBI with data from Oracle.
5
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Introduction to Oracle. Oracle is a relational database that is very popular in the corporate world and runs most of the world’s most critical systems from insurance to banking to manufacturing. The version of Oracle we will be using is Oracle 11g express edition which is a free version as it has limits to the amount of data that you can store into it. First we will need to download the Oracle database software as shown below.
Oracle express download Steps. 1. Download Oracle Express from the Oracle website (www.oracle.com)
Click to download oracle express 2. Accept the Oracle download license then select your download version. If you are not already registered at oracle.com, you may need to create an account. Next select the download version. I am on windows so I will select the windows 32 bit version.
6
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
3. The download should commence. This is a 312MB file so should not take long.
4. Extract the downloaded files and double click on setup.
5. On the welcome screen click Next.
7
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
6. Accept the license and click next.
7. Specify the installation directory and click Next.
8
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
8. Enter the password that will be used for SYS and SYSTEM user. (These are database admin accounts in case you have not used Oracle before)
9. On the summary screen, click install.
9
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
10. It will take a moment to install. Once it is done, you should see this screen. Click on finish.
Oracle SQL Developer. We will need a tool to use in managing the database and writing queries. Go back to the oracle.com account and download SQL Developer. Here are the steps. 10
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
1. Navigate to www.oracle.com, under Downloads, select SQL Developer.
2. Accept the OTN License Agreement. 3. Select Windows 32-bit - zip file includes the JDK1.6.0_35 or the one for your platform.
4. Extract the downloaded file to C:\sqldeveloper for example. Double click on sqldeveloper.
11
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
5. When asked which files to associate with SQL Developer, select all.
Now we need to unlock the hr account in the installed Oracle database so that we can use it for our examples. HR is a schema that comes preinstalled with the database and it already has data that can be used for training and demonstration. Proceed as under. 12
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
1. Click Start-> All Programs -> Oracle 11g Express Edition -> Run SQL Command Line.
2. Connect as user sys by typing “connect sys as sysdba”. For the password, enter the same password you used during installation.
3. To unlock the user scott, use the statement “alter user hr account unlock”
4. Change the hr user password by using the statement “alter user hr identified by hr”
5. That’s it. We are done with DOS and black screens for now. Go back to SQL Developer, right click on Connections and select new connection.
13
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
6. Enter the data as shown. a. For connection name enter SpagoBI. b. Username hr. c. Password hr. d. Click on save password. e. Hostname localhost. f. Port 1521. g. SID xe. h. Click on Save then Connect.
7. Let’s try a simple query “select * from employees” to list all employees.
14
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Now we have all the tools needed for using SpagoBI with Oracle but before you begin, we need to change the Oracle Apex Port. Login as sysdba user and change the port to 80 as shown below. This is because by default it uses port 8080 which is also used by SpagoBI and we do not want them to conflict.
15
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
OLAP with JPIVOT OBJECTIVES After completing this chapter, you should be able to: 1. Describe the importance of OLAP to your business. 2. Use JPIVOT. 3. Use Mondrian cubes.
CONTENTS OLAP with JPIVOT. • • • •
Introduction to Online Analytical Processing (OLAP) OLAP cubes. Star and Mondrian Schema. Step by step example.
16
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
We will be creating an OLAP CUBE to enable us analyze salaries by departments. If you do not know about OLAB in SpagoBI then see my book “SpagoBI in two hours” or contact me at
[email protected]. Steps. 1. Login to Jdeveloper and create the view dep_salary using the query below. create view dep_salary as (select dep.department_name,emp.first_name||' '||emp.last_name as "Full Name",emp.salary from employees emp,departments dep where emp.department_id=dep.department_id);
17
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Create the xml schema below for your OLAP.
Once you have created the schema, you need to tell SpagoBi server where the schema file exists. Navigate to the root directory of your SpagoBI installation, in my case C:\All-In-One-SpagoBI-3.6.031102012\SpagoBI-DEMO-3.6.0. We will call this the $SPAGO_ROOT directory. Inside $SPAGO_ROOT, navigate to resources\Olap folder. Save your Mondrian schema here. Give it a name like Salary.xml. Next, you have to add to the engine-config.xml file the schema you just created. Navigate to $SPAGO_ROOT \webapps\SpagoBIJPivotEngine\WEB-INF\classes folder. Inside there, you will find the file engine-config.xml. Open it using your favorite text editor and add the following lines. The line should be added between the …. tags. You have to restart your SpagoBI server for the changes to take effect. Once the server have been restarted, login to the url http://servername:8080/SpagoBI and login using the username biadmin and password biadmin.
18
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Navigate to Resources-> Data source. On the extreme right, click on insert button to create a new data source.
Test the connection. Should be Ok, and then Save.
19
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
We will be using this data source for the remainder of the book. Now we will create a folder where all our OLAP documents will be stored. Click on Analytical Model -> Functionalities Management. Click on Functionalities then Insert. We will create a folder called OLAP as shown below.
Finally we will create the OLAP document itself. Click on Analytical Model -> Documents Development. Click on Insert button.
20
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
Under Show document templates (on the right) click on OLAP Documents. Save the document.
21
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
If you get the error “326: Resultset overflow occured 327:” then modify your Mondrian.properties field mondrian.result.limit=0 or a higher value. You might also get the error below which is caused by not using uppercase for column names in your xml file. org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${query01.result.overflowOccured}": An error occurred while getting property "result" from an instance of class com.tonbeller.jpivot.tags.OlapModelProxy (com.tonbeller.jpivot.olap.model.OlapException: mondrian.olap.MondrianException: Mondrian Error:Internal error: Error while executing query [select {[Measures].[Salary]} ON COLUMNS, {[Department]} ON ROWS from [SalaryComparison] ])
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test" with value "${query01.result.overflowOccured}": An error occurred while getting property "result" from an instance of class com.tonbeller.jpivot.tags.OlapModelProxy (com.tonbeller.jpivot.olap.model.OlapException: mondrian.olap.MondrianException: Mondrian Error:Internal error: Error while executing query [select {[Measures].[Salary]} ON COLUMNS, {[Department]} ON ROWS from [SalaryComparison] ])
22
OGUTU.ORG P.O.Box 8031-00200 Nairobi Kenya
Email:
[email protected] Web: www.ogutu.org
For example, this will throw the error above since the columns salary and department_name are in lower case. You should now get this screen. So the average salary for all departments is 6,457.
Let’s collapse the departments.
And there you have it. Your first OLAP using SpagoBI and Oracle. For other topics, see the book “SpagoBi in two hours” and let the sky be the limit. Contact us at
[email protected] on how to get this book. 23