多维数据分析之初体验

        因近期学习mondrian schema和mdx语法,学习历程较艰辛,故希望以系列文章予以记录,且方便今后查阅。
        书写schema的过程即是构造你的多维数据集的过程,此步相当重要,直接关系到今后查询时效率的高低,
好比建立一个糟糕的数据库,做复杂需求时,即便是神仙也只能“望库兴叹”,只可惜初涉此域,我也只能讲讲基本概念了,希望能帮助大家更好的理解多维数据集这么个玩意儿。
        先讲建立cube,cube即数据立方的意思,可以理解为数据仓库中被挑选出来当成研究对象的数据集,举个简单的例子:
        现有一张工资表salary,字段有id, customer_id, salary,id为该表主键,customer_id为该表外键,
连接到表customer,表结构为customer_id, gender,工资表即可当成一个简单的cube,cube中的事实表即Salary。
有了研究对象,接下来自然是确定研究角度了,研究角度对应于schema中的dimensions,dimension可以对应另一张表,也可以是cube中的事实表,
此例中将Customer当成维度表,维度表和事实表必须要有关联,否则毫无关系的两张表能擦出什么火花?!
        接下来你有了研究对象,有了研究角度,那到底该研究什么?这就对应于schema中的Measure(度量),此例中选择工资的综合为统计指标。

<Schema name="Salary">

              <Cube name="Salary" cache="true" enabled="true">

            <Table name="Salary" alias="">
           </Table>
          <Dimension type="StandardDimension" foreignKey="customer_id" name="Gender">
                <Hierarchy name="h1" hasAll="true" allMemberName="All Genders" primaryKey="customer_id">
                     <Table name="customer">
                     </Table>
                     <Level name="Gender" table="customer" column="gender" uniqueMembers="true">
                     </Level>
                 </Hierarchy>
          </Dimension>
           <Measure name="Salary In Total" column="salary" aggregator="sum" visible="true">
          </Measure>

              </Cube>
        </Schema>

 

        这时你就可以从customer表中gender的角度统计salary表中工资总和了,即salary表中男性、女性以及未知性别的工资总额了。
        MDX查询语句为
        select {[Measures].[Salary In Total]} on columns,
                   {[Gender].[Gender].Members} on rows
        from [Salary]

        btw:文章没有细致讲语法,只是抛砖引玉而已。关于写mondrian schema的语法,详见http://mondrian.pentaho.com/documentation/schema.php
        关于mdx的语法及内置函数,详见http://msdn.microsoft.com/en-us/library/ms145970.aspx
        既然走上了这条“不归路”,这两个网站你想不去都不行了...

 

你可能感兴趣的:(数据结构,PHP,cache,Microsoft)