記天溯實(shí)習(xí)期間關(guān)于mondrian的開發(fā)小結(jié)
來源:程序員人生 發(fā)布時(shí)間:2015-07-14 13:55:22 閱讀次數(shù):3153次
點(diǎn)擊打開鏈接關(guān)于OLAP服務(wù)引擎的模塊開發(fā),已大致完成,此次工作也能夠放1段落,迎來51小長(zhǎng)假。
本文對(duì)本次開發(fā)做1次小的總結(jié),全部eway項(xiàng)目的整體架構(gòu)圖以下所示,OLAP引擎這塊用的是開源框架mondrian,也是本人負(fù)責(zé)的。


那末本模塊所要做的事情,就是接受從云端服務(wù)總線上傳輸過來的JSON格式,并進(jìn)行相應(yīng)的業(yè)務(wù)邏輯判斷、查詢并返回JSON格式。
因此,模塊的開發(fā)任務(wù),以下:
1.JSON報(bào)文的解析與生成;
2.數(shù)據(jù)倉庫的建立(mysql關(guān)系數(shù)據(jù)庫中建立相對(duì)應(yīng)的事實(shí)表和維度表)
3.邏輯模型的生成(通過schema-workbench工具生成,它終究是1個(gè)xml文件)
4.履行相干MDX語句,對(duì)邏輯模型進(jìn)行查詢操作。
1、任務(wù)的細(xì)化,JSON格式的定義及解析,我們采取的是開源框架FastJSON,它提倡建立與JSON格式相對(duì)應(yīng)的數(shù)據(jù)結(jié)構(gòu)
{
"Olaps": [{
"tenant": "tiansu",
"measurements": [
{
"measureName":"sum",
"measureName":"avg"
}
],
"dimentions": [
{
"dim":"region",
"Levels": [
{
"province": "江蘇",
"city": "南京",
"district": "玄武",
"building": "1號(hào)建筑",
"area": "1號(hào)區(qū)域"
}
]
},
{
"dim":"time",
"Levels": [
{
"year": "2015",
"month": "1",
"week":"2",
"day":"21",
"hour":"13",
"minute":"24"
}
]
},
{
"dim":"category",
"hierarchys":[{"hierarchy":"category_by_type"}],
"Levels": [
{
"categoryTypeName": "動(dòng)力"
}
]
}
],
"conditions":[
{
"dim":"region",
"hierarchys":[{"hierarchyName":"region_by_area"}],
"Levels": [
{
"province": "江蘇",
"city": "南京",
"district": "玄武",
"building": "1號(hào)建筑",
"area": "1號(hào)區(qū)域"
}
]
},
{
"dim":"time",
"hierarchys":[{"hierarchyName":"time_by_day"},{"hierarchyName":"time_by_week"}],
"Levels": [
{
"year": "2015",
"month": "1",
"week":"2",
"day":"21",
"hour":"13",
"minute":"24"
}
]
},
{
"dim":"category",
"hierarchys":[{"hierarchyName":"category_by_type"}],
"Levels": [
{
"categoryTypeName": "動(dòng)力"
}
]
}
]
}
]
}
{"Olaps":[ ]}對(duì)這類數(shù)據(jù)結(jié)構(gòu),我是這樣來構(gòu)造它的javaBean的,首先通過類Eway來表示{ },并將olaps這個(gè)數(shù)組包括進(jìn)去。[ ]表示數(shù)組。
而對(duì)與{"Levels":[{""year": "2015", "month": "1" } ] }這類情勢(shì)的數(shù)據(jù)結(jié)構(gòu),我們用list<Map<String,String>>來表示。由于數(shù)組中存在太多的變量。
下面是以上全部Json對(duì)應(yīng)的JavaBean文件
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<Hierarchy> hierarchys;
private List<Map<String,String>> levels;
....
}
2、數(shù)據(jù)倉庫的建立
本項(xiàng)目中有以下維度:時(shí)間維、地區(qū)維和能源種類維
全部數(shù)據(jù)倉庫是建立在Mysql關(guān)系數(shù)據(jù)庫當(dāng)中的,建表語句以下:
DROP TABLE IF EXISTS `dim_class`;
CREATE TABLE `dim_class` (
`class_id` int(10) unsigned NOT NULL auto_increment,
`class` varchar(255) default NULL COMMENT '分類名稱',
PRIMARY KEY (`class_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dim_class
-- ----------------------------
INSERT INTO `dim_class` VALUES ('1', '動(dòng)力');
INSERT INTO `dim_class` VALUES ('2', '照明');
INSERT INTO `dim_class` VALUES ('3', '空調(diào)');
INSERT INTO `dim_class` VALUES ('4', '其他');
-- ----------------------------
-- Table structure for `dim_org`
-- ----------------------------
DROP TABLE IF EXISTS `dim_org`;
CREATE TABLE `dim_org` (
`org_id` int(10) unsigned NOT NULL auto_increment COMMENT '組織維主ID',
`group` varchar(255) default NULL COMMENT '組織--團(tuán)體',
`company` varchar(255) default NULL COMMENT '組織--公司',
`branch` varchar(255) default NULL COMMENT '組織--分支',
`department` varchar(255) default NULL COMMENT '組織--部門',
PRIMARY KEY (`org_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dim_org
-- ----------------------------
INSERT INTO `dim_org` VALUES ('1', '天溯', '研發(fā)中心', '系統(tǒng)軟件部', '通訊組');
INSERT INTO `dim_org` VALUES ('2', '天溯', '研發(fā)中心', '系統(tǒng)軟件部', '企業(yè)組');
INSERT INTO `dim_org` VALUES ('3', '天溯', '研發(fā)中心', '系統(tǒng)軟件部', '云端組');
INSERT INTO `dim_org` VALUES ('4', '天溯', '研發(fā)中心', '系統(tǒng)軟件部', '利用組');
INSERT INTO `dim_org` VALUES ('5', '天溯', '研發(fā)中心', '產(chǎn)品部', '測(cè)試組');
INSERT INTO `dim_org` VALUES ('6', '天溯', '研發(fā)中心', '產(chǎn)品部', 'UCD');
INSERT INTO `dim_org` VALUES ('7', '天溯', '研發(fā)中心', '產(chǎn)品部', '產(chǎn)品計(jì)劃組');
INSERT INTO `dim_org` VALUES ('8', '天溯', '銷服中心', '交付運(yùn)維部', '工程技術(shù)組');
INSERT INTO `dim_org` VALUES ('9', '天溯', '銷服中心', '交付運(yùn)維部', '深化設(shè)計(jì)組');
INSERT INTO `dim_org` VALUES ('10', '天溯', '銷服中心', '交付運(yùn)維部', '運(yùn)維服務(wù)組');
-- ----------------------------
-- Table structure for `dim_region`
-- ----------------------------
DROP TABLE IF EXISTS `dim_region`;
CREATE TABLE `dim_region` (
`region_id` int(10) unsigned NOT NULL auto_increment,
`province` varchar(255) default NULL COMMENT '區(qū)域--省',
`city` varchar(255) default NULL COMMENT '區(qū)域--市',
`district` varchar(255) default NULL COMMENT '區(qū)域--區(qū)縣',
`building` varchar(255) default NULL COMMENT '區(qū)域--建筑體',
`area` varchar(255) default NULL COMMENT '區(qū)域--建筑內(nèi)功能分區(qū)',
PRIMARY KEY (`region_id`)
) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dim_region
-- ----------------------------
INSERT INTO `dim_region` VALUES ('1', '江蘇', '南京', '玄武', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('2', '江蘇', '南京', '白下', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('3', '江蘇', '南京', '玄武', '1號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('4', '江蘇', '南京', '玄武', '1號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('5', '江蘇', '南京', '玄武', '2號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('6', '江蘇', '南京', '玄武', '2號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('7', '江蘇', '南京', '玄武', '2號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('8', '江蘇', '南京', '玄武', '3號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('9', '江蘇', '南京', '玄武', '3號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('10', '江蘇', '南京', '玄武', '3號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('11', '江蘇', '南京', '白下', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('12', '江蘇', '南京', '白下', '1號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('13', '江蘇', '南京', '白下', '1號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('14', '江蘇', '南京', '建鄴', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('15', '江蘇', '南京', '建鄴', '1號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('16', '江蘇', '南京', '建鄴', '1號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('17', '江蘇', '南京', '建鄴', '2號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('18', '江蘇', '南京', '建鄴', '2號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('19', '江蘇', '南京', '建鄴', '2號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('20', '江蘇', '南京', '建鄴', '3號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('21', '江蘇', '南京', '建鄴', '3號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('22', '江蘇', '南京', '建鄴', '3號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('23', '江蘇', '南京', '建鄴', '4號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('24', '江蘇', '南京', '建鄴', '5號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('25', '江蘇', '南京', '建鄴', '6號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('26', '湖南', '長(zhǎng)沙', '開福', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('27', '湖南', '長(zhǎng)沙', '開福', '1號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('28', '湖南', '長(zhǎng)沙', '開福', '1號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('29', '湖南', '長(zhǎng)沙', '開福', '2號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('30', '湖南', '長(zhǎng)沙', '開福', '2號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('31', '湖南', '長(zhǎng)沙', '開福', '2號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('32', '湖南', '長(zhǎng)沙', '開福', '3號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('33', '湖南', '長(zhǎng)沙', '開福', '3號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('34', '湖南', '長(zhǎng)沙', '開福', '3號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('35', '湖南', '長(zhǎng)沙', '開福', '4號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('36', '湖南', '長(zhǎng)沙', '開福', '5號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('37', '湖南', '長(zhǎng)沙', '開福', '6號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('38', '湖南', '長(zhǎng)沙', '雨花', '1號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('39', '湖南', '長(zhǎng)沙', '雨花', '1號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('40', '湖南', '長(zhǎng)沙', '雨花', '1號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('41', '湖南', '長(zhǎng)沙', '雨花', '2號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('42', '湖南', '長(zhǎng)沙', '雨花', '2號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('43', '湖南', '長(zhǎng)沙', '雨花', '2號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('44', '湖南', '長(zhǎng)沙', '雨花', '3號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('45', '湖南', '長(zhǎng)沙', '雨花', '3號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('46', '湖南', '長(zhǎng)沙', '雨花', '3號(hào)建筑', '3號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('47', '湖南', '長(zhǎng)沙', '雨花', '4號(hào)建筑', '1號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('48', '湖南', '長(zhǎng)沙', '雨花', '5號(hào)建筑', '2號(hào)區(qū)域');
INSERT INTO `dim_region` VALUES ('49', '湖南', '長(zhǎng)沙', '雨花', '6號(hào)建筑', '3號(hào)區(qū)域');
-- ----------------------------
-- Table structure for `dim_time`
-- ----------------------------
DROP TABLE IF EXISTS `dim_time`;
CREATE TABLE `dim_time` (
`time_id` int(10) unsigned NOT NULL auto_increment COMMENT '時(shí)間維度ID',
`year` int(10) default NULL COMMENT '時(shí)間--年',
`quarter` int(10) default NULL COMMENT '時(shí)間--季度',
`month` int(10) default NULL COMMENT '時(shí)間--月',
`day` int(10) default NULL COMMENT '時(shí)間--日',
`week` int(10) default NULL COMMENT '時(shí)間--周',
`weekday` int(10) default NULL COMMENT '時(shí)間--1周中的日數(shù),0為星期1,6為星期日',
`hour` int(10) default NULL COMMENT '時(shí)間--小時(shí),采取24小時(shí)制',
`minute` int(10) default NULL COMMENT '時(shí)間--分鐘',
PRIMARY KEY (`time_id`)
) ENGINE=InnoDB AUTO_INCREMENT=349 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dim_time
-- ----------------------------
INSERT INTO `dim_time` VALUES ('1', '2015', '1', '1', '1', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('2', '2015', '2', '1', '2', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('3', '2015', '3', '1', '3', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('4', '2015', '4', '1', '4', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('5', '2015', '5', '1', '5', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('6', '2015', '6', '1', '6', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('7', '2015', '5', '2', '7', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('8', '2015', '6', '1', '8', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('9', '2015', '1', '1', '9', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('10', '2015', '1', '1', '10', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('11', '2015', '1', '1', '11', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('12', '2015', '1', '1', '12', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('13', '2015', '1', '1', '13', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('14', '2015', '1', '1', '14', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('15', '2015', '1', '1', '15', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('16', '2015', '1', '1', '16', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('17', '2015', '1', '1', '17', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('18', '2015', '1', '1', '18', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('19', '2015', '1', '1', '19', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('20', '2015', '1', '1', '20', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('21', '2015', '1', '1', '21', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('22', '2015', '1', '1', '22', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('23', '2015', '1', '1', '23', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('24', '2015', '1', '1', '24', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('25', '2015', '1', '1', '25', null, null, '0', '0');
INSERT INTO `dim_time` VALUES ('26', '2015', '1', '1', '26', null, null, '0', '0');
3、建立與之對(duì)應(yīng)的邏輯模型
可以參考之前的文章http://blog.csdn.net/qzp1991/article/details/44017161
4、相干的MDX語句
可以查看之前的文章http://blog.csdn.net/qzp1991/article/details/44776523
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)