A summary of the development of Mondrian during the practice of Tian-su

Source: Internet
Author: User

Click to open the link about OLAP Services engine module development, has been roughly completed, this work can also put a paragraph, ushered in 51 small holiday.

This article on the development of a small summary, the whole eway project of the overall structure of the diagram as shown below, the OLAP engine is open source framework Mondrian, but also I am responsible for.


So what this module is going to do is accept the JSON format transmitted from the cloud service bus, and make the corresponding business logic judgment, query and return the JSON format.

Therefore, the module development task is as follows:

Parsing and generation of 1.JSON messages;

2. Establishment of the Data Warehouse (the corresponding fact table and dimension table are established in MySQL relational database)

3. Generation of the logical model (generated by the Schema-workbench tool, which is ultimately an XML file)

4. Execute the relevant MDX statement to query the logical model.

I. Task refinement, JSON format definition and parsing, we are using the Open source framework Fastjson, which advocates the creation of a data structure corresponding to the JSON format

{"Olaps": [{"Tenant": "Tiansu", "measurements": [{"Measurename": "Sum", "MEAs                    Urename ":" Avg "}]," dimentions ": [{" Dim ":" Region "," levels ": [ {"Province": "Jiangsu", "City": "Nanjing", "Distr"                ICT ":" Xuanwu "," Building ":" Building No. 1th "," area ":" Zone 1th "} ]}, {"Dim": "Time", "levels": [{"Y                Ear ":", "Month": "1", "Week": "2", "Day": "+", "Hour": "$", "minute": "24"} ]}, {"Dim": "Category", "Hierarchys": [{"Hierarchy": "Category_by_type"}], "            Levels ": [{" Categorytypename ":" Power "}] }], "Conditions ": [{" Dim ":" Region "," Hierarchys ": [{" Hierarchyname ":" Region_by_area "}]," Levels ": [ {"Province": "Jiangsu", "City": "Nanjing", "District": "Xuanwu"            , "Building": "Building No. 1th", "area": "Zone 1th"}]                }, {"Dim": "Time", "Hierarchys": [{"Hierarchyname": "Time_by_day"},{"Hierarchyname": "Time_by_week"}], "Levels": [{"Year": "+", "month": "1", "W Eek ":" 2 "," Day ":" + "," Hour ":" $ "," minute ":" ""} "}, {" Dim ":" Categ                        Ory "," Hierarchys ": [{" Hierarchyname ":" Category_by_type "}]," levels ": [{ "Categorytypename": "Power"}]}]}]}
{"Olaps": []} for this kind of data structure, this is how I construct its JavaBean, first through the class eWAY to represent {}, and to include the Olaps array. [] represents an array.

And on with {"Levels": [{"" Year ":", "" Month ":" 1 "}]} This form of data structure, we use list<map<string,string>> to represent. Because there are too many variables in the array.

Here is the JavaBean file for the entire JSON above

public class eWAY {private list<olap> olaps;public list<olap> getolaps () {return olaps;} public void Setolaps (list<olap> olaps) {this.olaps = Olaps;}}

public class Olap {private String tenant;private list<measurement> measurements;private list<dimention> Dimentions;private list<condition> conditions;        ....}
public class Measurement {private string Measurename;public string Getmeasurename () {return measurename;} public void Setmeasurename (String measurename) {this.measurename = Measurename;}}
public class Dimention {private String dim;private list<map<string,string>> levels;        .....}
public class Condition {private String dim;private list

Second, the establishment of data warehouse

This project has the following dimensions: Time dimension, regional peacekeeping energy type dimension

The entire data warehouse is built into the MySQL relational database, with the following table statements:

DROP TABLE IF EXISTS ' Dim_class '; CREATE TABLE ' dim_class ' (' class_id ' int (ten) unsigned NOT NULL auto_increment, ' class ' varchar (255) Default NULL commen T ' category name ', PRIMARY KEY (' class_id ')) Engine=innodb auto_increment=5 DEFAULT Charset=utf8;------------------------------ --Records of Dim_class------------------------------insert INTO ' dim_class ' VALUES (' 1 ', ' power '); insert INTO ' Dim_class ' V Alues (' 2 ', ' illumination '); insert INTO ' dim_class ' values (' 3 ', ' air conditioning '); insert INTO ' dim_class ' values (' 4 ', ' other ');----------------- ---------------table structure for ' dim_org '------------------------------DROP table IF EXISTS ' dim_org '; CREATE TABLE ' dim_org ' (' org_id ' int (ten) unsigned not NULL auto_increment COMMENT ' organization dimension Master ID ', ' Group ' varchar (255) Defaul T NULL COMMENT ' organization-group ', ' Company ' varchar (255) default NULL COMMENT ' organization-corporate ', ' branch ' varchar (255) default NULL Commen T ' organization-branch ', ' Department ' varchar (255) Default NULL COMMENT ' organization-department ', PRIMARY KEY (' org_id ')) Engine=innodb Auto_increme Nt=11 DEfault Charset=utf8;--------------------------------Records of dim_org------------------------------INSERT into ' Dim_org ' VALUES (' 1 ', ' retrospective ', ' Research Center ', ' system software Department ', ' distribution group '), INSERT into ' dim_org ' values (' 2 ', ' Days ', ' Research Center ', ' system software Department ', ' Enterprise Group '); Inser T into ' dim_org ' values (' 3 ', ' Day retrospective ', ' Research Center ', ' system software Department ', ' Cloud Group '), INSERT into ' dim_org ' values (' 4 ', ' Days Back ', ' Research Center ', ' system software Department ', ' application Group ') Insert INTO ' dim_org ' values (' 5 ', ' retrospective ', ' Research Center ', ' product Department ', ' Test team '), insert INTO ' dim_org ' values (' 6 ', ' Days ', ' Research Center ', ' product ', ' UCD '); insert INTO ' dim_org ' values (' 7 ', ' retrospective ', ' Research Center ', ' product Department ', ' Product Planning Group '); insert INTO ' dim_org ' values (' 8 ', ' Days ', ' service center ', ' Delivery Operations department ', ' Engineering Technology Group '); insert INTO ' dim_org ' values (' 9 ', ' retrospective ', ' pin center ', ' delivery operations ', ' deepening Design Group '); insert INTO ' dim_org ' values (' 10 ', ' Day "Service Center", ' delivery Operations department ', ' operation and maintenance services Group ');--------------------------------Table structure for ' dim_region '---------------------- --------DROP TABLE IF EXISTS ' dim_region '; CREATE TABLE ' dim_region ' (' region_id ' int (ten) unsigned not NULL auto_increment, ' Province ' varchar (255) Default Null COMMENT ' zone--province ', ' City ' varchar (255) default null COMMENT ' zone-municipal ', ' District ' varchar (255) default NULL COMMENT ' Region-District ', ' Building ' varchar (255) default null COMMENT ' area-architecture ', ' area ' varchar (255) default null COMMENT ' zone--architectural functional partition ' , PRIMARY KEY (' region_id ')) Engine=innodb auto_increment=50 DEFAULT Charset=utf8;--------------------------------Rec Ords of Dim_region------------------------------INSERT into ' dim_region ' VALUES (' 1 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 1th buildings ', ' Area 1th '); Nsert into ' dim_region ' values (' 2 ', ' Jiangsu ', ' Nanjing ', ' Baixia ', ' 1th building ', ' 1th area '); INSERT into ' dim_region ' values (' 3 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' Building No. 1th ', ' area 2nd '); insert INTO ' dim_region ' VALUES (' 4 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 1th buildings ', ' 3rd '); insert INTO ' dim_region ' VALU ES (' 5 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 2nd buildings ', ' 1th area '); insert INTO ' dim_region ' VALUES (' 6 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 2nd buildings ', ' 2nd '); insert Into ' dim_region ' values (' 7 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 2nd buildings ', ' 3rd area '); INSERT into ' dim_region ' values (' 8 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' Building No. 3rd ', area ' 1th '); INSERT INTO ' dim_region ' values (' 9 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 3rd buildings ', ' 2nd area '); INSERT into ' dim_region ' values (' 10 ', ' Jiangsu ', ' Nanjing ', ' Xuanwu ', ' 3rd ') Building ', ' area 3rd '); insert INTO ' dim_region ' values (' 11 ', ' Jiangsu ', ' Nanjing ', ' Baixia ', ' 1th buildings ', ' 1th '); insert INTO ' dim_region ' values (' 12 ', ' Jiangsu ', ' Nanjing ', ' baixia ', ' Building 1th ', ' area 2nd '); insert INTO ' dim_region ' VALUES (' 13 ', ' Jiangsu ', ' Nanjing ', ' Baixia ', ' 1th buildings ', ' 3rd '); INSERT into ' Dim_region ' values (' 14 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 1th buildings ', ' 1th area '); INSERT into ' dim_region ' values (' 15 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 1th ') ' 2nd '); insert INTO ' dim_region ' values (' 16 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 1th buildings ', ' 3rd area '); insert INTO ' dim_region ' values (' 17 ' , ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 2nd building ', ' 1th area '); insert INTO ' dim_region ' VALUES (' 18 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 2nd buildings ', ' 2nd '); INSERT INTO ' Dim_region ' VALUES (' 19 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 2nd buildings ', ' area 3rd '); INSERT into ' dim_region ' values (' 20 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 3rd ' building  ', ' area 1th '); insert INTO ' dim_region ' values (' 21 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 3rd ', ' 2nd area '); insert INTO ' dim_region ' values (' 22 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' No. 3rd Building', ' area 3rd '); insert INTO ' dim_region ' values (' 23 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 4th ', ' 1th area '); insert INTO ' dim_region ' values (' 24 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' Building 5th ', ' area 2nd '); insert INTO ' dim_region ' VALUES (' 25 ', ' Jiangsu ', ' Nanjing ', ' Jianye ', ' 6th buildings ', ' 3rd area '); INSERT INTO ' d Im_region ' VALUES (' 26 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 1th buildings ', ' 1th '); INSERT into ' dim_region ' values (' 27 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 1th buildings ') , ' area 2nd '); insert INTO ' dim_region ' values (' 28 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 1th buildings ', ' 3rd area '); insert INTO ' dim_region ' values (' 29 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' Building 2nd ', ' Area 1th '); insert INTO ' dim_region ' VALUES (' 30 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 2nd buildings ', ' 2nd area '); insert INTO ' di  M_region ' VALUES (' 31 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 2nd buildings ', ' 3rd '); INSERT into ' dim_region ' values (' 32 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 3rd buildings ', ' Area 1th '); insert INTO ' dim_region ' values (' 33 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 3rd buildings ', ' 2nd area '); insert INTO ' dim_region ' values (' 34 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' Building 3rd ', ' area 3rd '); insert INTO ' dim_region ' VALUES (' 35 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 4th buildings ', ' 1th '); insert INTO ' dim _region ' VALUES (' 36 ', 'Hunan ', ' Changsha ', ' Kaifu ', ' Building 5th ', ' area 2nd '); insert INTO ' dim_region ' VALUES (' 37 ', ' Hunan ', ' Changsha ', ' Kaifu ', ' 6th buildings ', ' 3rd '); insert INTO ' dim _region ' VALUES (' 38 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 1th buildings ', ' 1th '); INSERT into ' dim_region ' values (' 39 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 1th buildings ', ' Area 2nd '); insert INTO ' dim_region ' values (' 40 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 1th buildings ', ' 3rd area '); insert INTO ' dim_region ' values (' 41 ', ' lake South ', ' Changsha ', ' Yuhua ', ' Building 2nd ', ' Area 1th '); insert INTO ' dim_region ' VALUES (' 42 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 2nd buildings ', ' 2nd '); INSERT INTO ' dim_ Region ' VALUES (' 43 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 2nd buildings ', ' 3rd '); INSERT into ' dim_region ' values (' 44 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 3rd buildings ', ' Area 1th '); insert INTO ' dim_region ' values (' 45 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 3rd buildings ', ' 2nd area '); insert INTO ' dim_region ' values (' 46 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' Building 3rd ', ' area 3rd '); insert INTO ' dim_region ' VALUES (' 47 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 4th buildings ', ' Area 1th '); insert INTO ' Dim_r Egion ' VALUES (' 48 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 5th buildings ', ' 2nd '); INSERT into ' dim_region ' values (' 49 ', ' Hunan ', ' Changsha ', ' Yuhua ', ' 6th buildings ', ' 3 Area ');--------------------------------table structure for ' dim_time '------------------------------DROP table IF EXISTS ' dim_time '; CREATE TABLE ' dim_time ' (' time_id ' int (ten) unsigned not NULL auto_increment COMMENT ' Time dimension ID ', ' year ' int (Ten) default NU LL COMMENT ' time-year ', ' Quarter ' int (TEN) default null COMMENT ' time-quarter ', ' month ' int (TEN) default null COMMENT ' time-month ', ' Day ' Int (ten) default null COMMENT ' Time-day ', ' Week ' int (TEN) default null COMMENT ' time-week ', ' weekday ' int (TEN) default null COMM ENT ' Time--the number of days of the week, 0 is Monday, 6 is Sunday ', ' Hour ' int (ten) default null COMMENT ' time-hour, in 24-hour system ', ' minute ' int (ten) default null Commen T ' time-minutes ', PRIMARY KEY (' time_id ')) Engine=innodb auto_increment=349 DEFAULT Charset=utf8;--------------------------- -----Records of Dim_time------------------------------INSERT into ' dim_time ' VALUES (' 1 ', ' + ', ' 1 ', ' 1 ', ' 1 ', NULL, n ull, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' 2 ', ' n ', ' 2 ', ' 1 ', ' 2 ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VAL UES (' 3 ', ' + ', ' 3 ', ' 1 ', ' 3 ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' 4 ', ' N ', ' 4 ', ' 1 ', ' 4 ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' V Alues (' 5 ', ' N ', ' 5 ', ' 1 ', ' 5 ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' 6 ', ' n ', ' 6 ', ' 1 ', ' 6 ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' 7 ', ' N ', ' 5 ', ' 2 ', ' 7 ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VA Lues (' 8 ', ' N ', ' 6 ', ' 1 ', ' 8 ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' 9 ', ' n '), ' 1 ', ' 1 ', ' 9 ', null ull, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' n ', ' n ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' V Alues (' One ', ' n ', ' 1 ', ' 1 ', ' one ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' + ', ' n ', ' 1 ', ' 1 ', ' n ', Nu ll, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' Dim_ti Me ' values (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' dim_time ' values (' 15 ', ' 2015 ', ' 1 ', ' 1 ', ' 15 ', NULL, NULL, ' 0 ', ' 0 ')Insert INTO ' dim_time ' values (' + ', ' n ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' values (' 17 ', '  ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' values (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' values (' 2  0 ', ' n ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' + ', ' + ', ' 1 ', ' 1 ', ' + ', ' + '), NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' + ', ' n ', ' 1 ', ' 1 ', ' n ', null, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUE S (' + ', ' n ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); INSERT into ' Dim_time ' VALUES (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' + ', ' + ', ' 1 ', ' 1 ', ' + ', NULL, NULL, ' 0 ', ' 0 '); insert INTO ' dim_time ' VALUES (' + ', ' n ', ' 1 ', ' 1 ', ' n ', null, NULL, ' 0 ', ' 0 ');

Thirdly, establishing a logical model corresponding to it

You can refer to the previous article http://blog.csdn.net/qzp1991/article/details/44017161

IV. Related MDX statements

You can view the previous article http://blog.csdn.net/qzp1991/article/details/44776523

A summary of the development of Mondrian during the practice of Tian-su

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.