Summary: This article is mainly for one
Java
Open source project -
Mondrian
,
OLAP
Engine - technology use and related concepts make a brief introduction and description.
Keywords: Mondrian OLAP MDX
I. Introduction
MONDRIAN, MONTRAN Pitt 1872-1944 Dutch painter, works are characterized by staggered three primary colors, and his work includes new modelingism (1920), which has been very deep for the development of abstract art. influences. - Jinshan word is said.
However, this article is not discussed in this article is not the artist. What is MONDRIAN?
MONDRIAN is an open source project. A OLAP (online analysis processing) engine written with Java. It implements queries in MDX language, reads data from the relational database (RDBMS). The results are then displayed in a multi-dimensional manner through Java API.
We all know that online analysis processing (OLA) analyzes large amounts of data in real time. "Online" The meaning of the word is that even the relevant amount of data is huge - may be in GB-based - the system should also respond quickly to display results.
OLAP uses a multi-dimensional analysis technology. Although all the data stored in the relational database exists in the form of rows and columns, a cube can still be composed of axis (AXES) and cells (Cell).
In the above example, the time is a dimension, and the hierarchies below is divided into semi-annual, quarter level (Level).
Second, inductive understanding - run a small instance
We temporarily do not discuss some of the techniques used by Mondrian. We can start with a small example, don't care about every detail, just hope that everyone has a sense of sensibility. In the process of implementing this example, perhaps the reader can see some ends.
First, you should go to http://sourceforge.net/projects/mondrian/ to download the latest version of MONDRIAN. This is a ZIP package, including the lib and an example we have to use.
Of course, readers can run Mondrian's own instance, but this example is a bit complicated. In addition to Mondrian itself, there are other technologies in it, it is not easy to explain, and it is not suitable for beginners. Therefore, the author designs a simple and clean minimization example.
The instance environments described herein are Windows2000 Tomcat Oracle. And think that the reader has made the correct development environment for JDK and Tomcat.
2.1 Preparation Work
Establish MyWebApp, MyWebApp / Web-INF, MYWEBAPP / Web-INF / LIB, and sequential in% Tomcat% / WebApp /
Mondrian.war / web-inf / lib / mondrian.jar, javacup.jar, xalan.jar, junit.jar et al. Copy to% Tomcat_Home% / WebApps / MyWebApp / lib / under.
2.2 Database Structure
In this tiny system, the database has 3 tables TB_EMPLOYEE (staff table), TB_TIME (Timetable), TB_SALARY. The surface structure is as follows:
Drop Table TB_EMPLOYEE
Create Table TB_EMPLOYEE
(
EMPLOYEE_ID NUMBER, - Staff ID
EMPLOYEE_NAME VARCHAR2 (10) - Name of staff
);
Drop table tb_time;
Create Table TB_TIME
(
Time_id Number, - Time ID
THE_Year Char (4), - Year THE_MONTH CHAR (2) - Month
);
DROP TABLE TB_SALARY;
Create Table TB_salary
(
EMPLOYEE_ID NUMBER, - Staff ID
Time_id Number, - Time ID
SALARY NUMBER (19, 4) - Salary
);
Of course, in order to enable the system to operate, readers need to insert some data to the database table.
2.3 Writing a Schema file according to the structure of the database table
XML Version = "1.0"?>
Level>
Hierarchy>
Dimension>
Hierarchy>
Dimension>
Cube>
Schema>
File path is MyWebApp / Web-INF / MONDRIANTEST.XML
2.4 Using MDX query
MyWebApp / Mondriantest.jsp
1 <% @ Page Import = "Mondrian.olap. *"%>
<%
2 Connection Connection =
Drivermanager.getConnection
("Provider = mondrian;
JDBC = JDBC: Oracle: Thin: @ xxx.xxx.xxx.xxx: 1521: DBNAME
JDBCUSER = DBUSER;
JDBCPassword = dbpasswd;
Catalog = file: /// c: /tomcat4.1/webapps/mywebapp/web-inf/mondriantest.xml;
JDBCDRIVERS = Oracle.jdbc.driver.Oracledriver; ", NULL, FALSE);
3 string querystr =
"SELECT {[MeasureS]. [SALARY]} on columns,
{[Employee]. [EmployeeId] .members} on rows
"from cubetest";
4 query query = connection.Parsequery (querystr);
5 results = connection.execute (query);
Out.println ("Get Result");
%>
2.5 operation
Start Tomcat at this time, enter in the browser address bar
http: // localhost: 8080 / mywebapp / mondriantest.jsp.
Third, in-depth discussion
3.1 API
Mondrian provides an API interface for client applications for queries. These APIs will feel like they have used people who have used JDBC. The main difference is that the query language is different: MONDRIAN is MDX ('multi-dimensional expression'), while JDBC uses SQL.
Like JDBC, it is also necessary to establish a connection, form a query statement, and perform a query to get a few steps such as results set.
Let's take a look at Mondriantest.jsp code
Chapter 1: Import Mondrian.olap. *
This is the class introduced to the class you need. The DriverManager, Connection, Query, and Result you want to use are in this package. This package is generally located in Mondrian.jar.
Chapter 2: Connection Connection =
Drivermanager.getConnection
("Provider = mondrian;
JDBC = JDBC: Oracle: Thin: @ xxx.xxx.xxx.xxx: 1521: DBNAME
JDBCUSER = DBUSER;
JDBCPassword = dbpasswd;
Catalog = file: /// c: /tomcat4.1/webapps/mywebapp/web-inf/mondriantest.xml;
JDBCDRIVERS = Oracle.jdbc.driver.Oracledriver; ", NULL, FALSE);
Create a Connection instance through DRIVERMANAGER to establish a database connection.
Where JDBC = JDBC: Oracle: Thin: @ xxx.xxx.xxx.xxx: 1521: dbname; is the IP and library name of the database. JDBCUSER = DBUSER; sets database users. JDBCPassword = dbpasswd; set user password. and
Catalog = file: /// c: /tomcat4.1/webapps/mywebapp/web-inf/mondriantest.xml; is the path to the schema file to be corresponding to the MDX statement query
Third line: string querystr = "select {[measure]. [SALARY]} on columns,
{[Employee]. [EmployeeId] .members} on rows
"from cubetest";
Form a query statement of MDX. The form of the MDX statement is closely related to the setting of the Schema file. Of course, the formation of the Schema file is also determined by the database structure.
Query 4: query query = connection.parseQuery (querystr); analyze the MDX statement, whether it complies with the Schema file definition, database structure, and database data.
Chapter 5: Result Result = Connection.execute (Query); Execute Query to get the result set.
We found that Query is similar to the JDBC's Statement, and Result is like the ResultSet.
3.2 Schema
3.2.1 What is Schema
Schema defines a multi-dimensional database. A logical model is included, and the purpose of this logical model is to write a query statement of the MDX language. This logic model actually provides these concepts: Cubes, dimensions, level (Levels), and member (MEMBERS).
The Schema file is an XML file for editing this Schema. A logical model and a database physical model are formed in this file.
3.2.2 SCHEMA logical structure
3.2.2.1 CUBE
A Cube is a set area of a series of dimensions and measures. In CUBE, the common place of Dimension and Measure is a sharing of a fact sheet.
example:
.......
Cube>