Mondrian Olap Engine Partly Review
1. Consisted of 4 layers
n Presentation layer
Take charge of the end-user interaction in various presentation forms. The logic model is multidimensional 'grammar' of dimensions, measures and cells.
n Calculation layer
Validates and executes MDX queries. Query transformer.
n Aggregation layer
Manage aggregation in the cache.
n Storage layer
Usually is an RDBMS.
2. Aggregation strategy
General idea is to delegate unto the database what the database has. Thus the side-effect is loading data processing is easier, and the system is suited to do Olap on dataset changing in real time.
n Fact data is stored in the RDBMS
n Read aggregated data into the cache by submitting group by
queries
n Use materialized views as many as possible
3. APIs
n The Usage is similar to JDBC interfaces (see the following example)
n Use MDX, in place of SQL
n Presents the database schema as a set of objects: Schema, Cube, Dimension, Hierarchy, Level, Member
n Now suppot XML/A
Example:
/* establish a connection with Mondrian , submit an MDX query and retrieve the multi-dimension dataset from Mondrian . */ import mondrian.olap.*; import java.io.PrintWriter;
Connection connection = DriverManager.getConnection( "Provider= mondrian ;" + "Jdbc=jdbc:odbc:MondrianFoodMart;" + "Catalog=/WEB-INF/FoodMart.xml;", null, false); Query query = connection.parseQuery( "SELECT {[Measures].[Unit Sales], [Measures].[Store Sales]} on columns," + " {[Product].children} on rows " + "FROM [Sales] " + "WHERE ([Time].[1997].[Q1], [Store].[CA].[ San Francisco ])"); Result result = connection.execute(query); result.print(new PrintWriter(System.out));
|
4. MDX extensions
Mondrian extends Mdx in two aspects.
n Support parameters
This is done through the functions Parameter():
Parameter(<name>, <type>, <defaultValue>[, <description>])
For example:
/* the top 10 brands in California */ SELECT {[Measures].[Unit Sales]} on columns, TopCount([Product].[Brand].members, Parameter("Count", NUMERIC, 10, "Number of products to show"), ( Parameter("Region", [Store], [Store].[ USA ].[CA]), [Measures].[Unit Sales]) ) on rows FROM Sales |
n Extend Build in functions StrToSet and StrToTuple
Add a optional parameter <hierarchy> to the functions, thus user can get the result of the given hierarchy.
StrToSet(<String Expression>[, <Hierarchy>])
StrToTuple(<String Expression>[, <Hierarchy>])
5. Schema
Mondrian use xml files to define its schema, including Logical model, Physical model and the mapping between them.
n Logical Model: the structure of multi-dimensional database cubes, including dimensions, hierarchies, levels, and members.
n Physical Model: the source of the data
Example:
/* foodmart, Sales cube defination */ <Schema> <Cube name="Sales"> <Table name="sales_fact_1997"/> <Dimension name="Gender" foreignKey="customer_id"> <Hierarchy hasAll="true" allMemberName="All Genders" primaryKey="customer_id"> <Table name="customer"/> <Level name="Gender" column="gender" uniqueMembers="true"/> </Hierarchy> </Dimension> <Dimension name="Time" foreignKey="time_id"> <Hierarchy hasAll="false" primaryKey="time_id"> <Table name="time_by_day"/> <Level name="Year" column="the_year" type="Numeric" uniqueMembers="true"/> <Level name="Quarter" column="quarter" uniqueMembers="false"/> <Level name="Month" column="month_of_year" type="Numeric" uniqueMembers="false"/> </Hierarchy> </Dimension> <Measure name="Unit Sales" column="unit_sales" aggregator="sum" formatString="#,###"/> <Measure name="Store Sales" column="store_sales" aggregator="sum" formatString="#,###.##"/> </Cube> </Schema> |
Attention: You can write custom member readers to extend the datasource.