使用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": "Sales 2",             //此三项的含义同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":"Store Sales","runiqueName":"[Measures].[Store Sales]","rcaption":"Store Sales"}]},{"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":"Store Sales","runiqueName":"[Measures].[Store Sales]","rcaption":"Store Sales"}]},{"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":"Store Sales","runiqueName":"[Measures].[Store Sales]","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":"Store Sales","runiqueName":"[Measures].[Store Sales]","rcaption":"Store Sales"}]},{"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":"Store Sales","runiqueName":"[Measures].[Store Sales]","rcaption":"Store Sales"}]},{"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":"Store Sales","runiqueName":"[Measures].[Store Sales]","rcaption":"Store Sales"}]}]

 

 

 

附录2:Cube--Sales 2

{"cubeName":"Sales 2","cuniqueName":"[Sales 2]","ccaption":"Sales 2","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":"Product Family","luniqueName":"Product Family","lcaption":"Product Family","depth":1},{"levelName":"Product Department","luniqueName":"Product Department","lcaption":"Product Department","depth":2},{"levelName":"Product Category","luniqueName":"Product Category","lcaption":"Product Category","depth":3},{"levelName":"Product Subcategory","luniqueName":"Product Subcategory","lcaption":"Product Subcategory","depth":4},{"levelName":"Brand Name","luniqueName":"Brand Name","lcaption":"Brand Name","depth":5},{"levelName":"Product Name","luniqueName":"Product Name","lcaption":"Product Name","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":"Sales Count","muniqueName":"[Measures].[Sales Count]","mcaption":"Sales Count"},{"measureName":"Unit Sales","muniqueName":"[Measures].[Unit Sales]","mcaption":"Unit Sales"},{"measureName":"Store Sales","muniqueName":"[Measures].[Store Sales]","mcaption":"Store Sales"},{"measureName":"Store Cost","muniqueName":"[Measures].[Store Cost]","mcaption":"Store Cost"},{"measureName":"Customer Count","muniqueName":"[Measures].[Customer Count]","mcaption":"Customer Count"},{"measureName":"Profit","muniqueName":"[Measures].[Profit]","mcaption":"Profit"},{"measureName":"Profit last Period","muniqueName":"[Measures].[Profit last Period]","mcaption":"Profit last Period"}]}

 

 

附录3:Shared Dimension

{"sharedName":"Store Type","suniqueName":"[Store Type]","scaption":"Store Type","hierarchies":[{"HierarchyName":"Store Type","huniqueName":"Store Type","hcaption":"Store Type","levels":[{"levelName":"(All)","luniqueName":"[Store Type].[(All)]","lcaption":"(All)","depth":0},{"levelName":"Store Type","luniqueName":"[Store Type].[Store Type]","lcaption":"Store Type","depth":1}]}]}