首页 > 代码库 > 项目笔记——9.21
项目笔记——9.21
使用google的gson转换,在线验证可用,例子来自saiku-foodmart。
PS:此文档是倒着写的,所以应先看2再看1…
1.首先是cube和共享维度:
PS:相关代码在com.xxx.schema包下
以Cube:Sales 2为例,此cube包含以上内容,每个cube封装为一条JSON
完整版见 附录2。
格式化后的(节选):
{
"cubeName":"Sales 2",
"cuniqueName":"[Sales 2]",
"ccaption": "Sales2", //此三项的含义同2中的注释
"dimensions": [ //此cube中包含的维度
{
"dimenName":"Time",
"duniqueName": "[Time]",
"dcaption":"Time", //名字属性都是这三个
"hierarchies": [ //此维度中的hierarchy
{
"HierarchyName": "Time",
"huniqueName": "[Time]",
"hcaption": "Time",
"levels": [ //此hierarchy中的level
{
"levelName":"Year",
"luniqueName": "Year",
"lcaption": "Year",
"depth": 0
//depth:level的深度,数值越小范围越大,如0表示ALL
}
……
]
},
{
"HierarchyName": "Time.Weekly",
……
}
]
}
……
],
"measures": [
{
"measureName": "Sales Count",
"muniqueName": "[Measures].[Sales Count]",
"mcaption":"Sales Count"
}
……
]
}
共享维度的结构与此类似,demo版应该用不到,示例见 附录3。
PS:生成MDX语句的代码见包com.xxx.mdx,
前端需要传给后台的数据形式,见各类开头的长注释。
2.然后是查询的结果(cell):
PS:相关代码在com.xxx.result包下
选择Cube:Sales,拖选以下条件:
每行封装一个JSON,完整样例见后面 附录1:
取出第一行的第一个cell,格式化(左上,坐标0,0)
{
"value": "$22,553.64", //这个cell的值
"coordRow": 0, //行坐标
"coordColumn": 0, //列坐标
"columns": [ //列上的表头(可能有多层)
{
"cname": "CA",
"cuniqueName": "[Customers].[USA].[CA]",
"ccaption": "CA"
},
{ //如此处为第二个表头
"cname": "F",
"cuniqueName":"[Gender].[F]",
"ccaption": "F"
}
],
"rows": [ //行上的表头(此例只有一个)
{
"rname": "Profit",
"runiqueName": "[Measures].[Profit]",
"rcaption": "Profit"
}
]
}
其中column、row都有三个属性:
-name:简称,如F
-uniqueName:全称,如[Gender].[F]
-caption:显示在页面中的名字,如“女”,默认与-name相同
附录1:
第一行的:
[{"value":"$22,553.64","coordRow":0,"coordColumn":0,"columns":[{"cname":"CA","cuniqueName":"[Customers].[USA].[CA]","ccaption":"CA"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]},{"value":"$22,911.70","coordRow":0,"coordColumn":1,"columns":[{"cname":"CA","cuniqueName":"[Customers].[USA].[CA]","ccaption":"CA"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]},{"value":"$22,361.31","coordRow":0,"coordColumn":2,"columns":[{"cname":"OR","cuniqueName":"[Customers].[USA].[OR]","ccaption":"OR"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]},{"value":"$23,334.58","coordRow":0,"coordColumn":3,"columns":[{"cname":"OR","cuniqueName":"[Customers].[USA].[OR]","ccaption":"OR"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]},{"value":"$39,174.49","coordRow":0,"coordColumn":4,"columns":[{"cname":"WA","cuniqueName":"[Customers].[USA].[WA]","ccaption":"WA"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]},{"value":"$37,907.41","coordRow":0,"coordColumn":5,"columns":[{"cname":"WA","cuniqueName":"[Customers].[USA].[WA]","ccaption":"WA"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"Profit","runiqueName":"[Measures].[Profit]","rcaption":"Profit"}]}]
第二行:
[{"value":"37,480.50","coordRow":1,"coordColumn":0,"columns":[{"cname":"CA","cuniqueName":"[Customers].[USA].[CA]","ccaption":"CA"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"StoreSales"}]},{"value":"38,088.75","coordRow":1,"coordColumn":1,"columns":[{"cname":"CA","cuniqueName":"[Customers].[USA].[CA]","ccaption":"CA"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"StoreSales"}]},{"value":"37,230.43","coordRow":1,"coordColumn":2,"columns":[{"cname":"OR","cuniqueName":"[Customers].[USA].[OR]","ccaption":"OR"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"Store Sales"}]},{"value":"38,820.32","coordRow":1,"coordColumn":3,"columns":[{"cname":"OR","cuniqueName":"[Customers].[USA].[OR]","ccaption":"OR"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"StoreSales"}]},{"value":"65,063.54","coordRow":1,"coordColumn":4,"columns":[{"cname":"WA","cuniqueName":"[Customers].[USA].[WA]","ccaption":"WA"},{"cname":"F","cuniqueName":"[Gender].[F]","ccaption":"F"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"StoreSales"}]},{"value":"63,216.70","coordRow":1,"coordColumn":5,"columns":[{"cname":"WA","cuniqueName":"[Customers].[USA].[WA]","ccaption":"WA"},{"cname":"M","cuniqueName":"[Gender].[M]","ccaption":"M"}],"rows":[{"rname":"StoreSales","runiqueName":"[Measures].[StoreSales]","rcaption":"Store Sales"}]}]
附录2:Cube--Sales 2
{"cubeName":"Sales2","cuniqueName":"[Sales2]","ccaption":"Sales2","dimensions":[{"dimenName":"Time","duniqueName":"[Time]","dcaption":"Time","hierarchies":[{"HierarchyName":"Time","huniqueName":"[Time]","hcaption":"Time","levels":[{"levelName":"Year","luniqueName":"Year","lcaption":"Year","depth":0},{"levelName":"Quarter","luniqueName":"Quarter","lcaption":"Quarter","depth":1},{"levelName":"Month","luniqueName":"Month","lcaption":"Month","depth":2}]},{"HierarchyName":"Time.Weekly","huniqueName":"[Time.Weekly]","hcaption":"Weekly","levels":[{"levelName":"(All)","luniqueName":"(All)","lcaption":"(All)","depth":0},{"levelName":"Year","luniqueName":"Year","lcaption":"Year","depth":1},{"levelName":"Week","luniqueName":"Week","lcaption":"Week","depth":2},{"levelName":"Day","luniqueName":"Day","lcaption":"Day","depth":3}]}]},{"dimenName":"Product","duniqueName":"[Product]","dcaption":"Product","hierarchies":[{"HierarchyName":"Product","huniqueName":"[Product]","hcaption":"Product","levels":[{"levelName":"(All)","luniqueName":"(All)","lcaption":"(All)","depth":0},{"levelName":"ProductFamily","luniqueName":"ProductFamily","lcaption":"ProductFamily","depth":1},{"levelName":"ProductDepartment","luniqueName":"ProductDepartment","lcaption":"Product Department","depth":2},{"levelName":"ProductCategory","luniqueName":"ProductCategory","lcaption":"ProductCategory","depth":3},{"levelName":"ProductSubcategory","luniqueName":"ProductSubcategory","lcaption":"ProductSubcategory","depth":4},{"levelName":"BrandName","luniqueName":"BrandName","lcaption":"BrandName","depth":5},{"levelName":"ProductName","luniqueName":"ProductName","lcaption":"ProductName","depth":6}]}]},{"dimenName":"Gender","duniqueName":"[Gender]","dcaption":"Gender","hierarchies":[{"HierarchyName":"Gender","huniqueName":"[Gender]","hcaption":"Gender","levels":[{"levelName":"(All)","luniqueName":"(All)","lcaption":"(All)","depth":0},{"levelName":"Gender","luniqueName":"Gender","lcaption":"Gender","depth":1}]}]}],"measures":[{"measureName":"SalesCount","muniqueName":"[Measures].[SalesCount]","mcaption":"SalesCount"},{"measureName":"UnitSales","muniqueName":"[Measures].[UnitSales]","mcaption":"UnitSales"},{"measureName":"StoreSales","muniqueName":"[Measures].[StoreSales]","mcaption":"StoreSales"},{"measureName":"StoreCost","muniqueName":"[Measures].[StoreCost]","mcaption":"StoreCost"},{"measureName":"CustomerCount","muniqueName":"[Measures].[CustomerCount]","mcaption":"CustomerCount"},{"measureName":"Profit","muniqueName":"[Measures].[Profit]","mcaption":"Profit"},{"measureName":"Profitlast Period","muniqueName":"[Measures].[Profit lastPeriod]","mcaption":"Profit last Period"}]}
附录3:Shared Dimension
{"sharedName":"StoreType","suniqueName":"[StoreType]","scaption":"Store Type","hierarchies":[{"HierarchyName":"StoreType","huniqueName":"StoreType","hcaption":"StoreType","levels":[{"levelName":"(All)","luniqueName":"[StoreType].[(All)]","lcaption":"(All)","depth":0},{"levelName":"StoreType","luniqueName":"[Store Type].[StoreType]","lcaption":"StoreType","depth":1}]}]}
项目笔记——9.21