1、简介
前几篇博客已经介绍了saiku、mondrian、MDX和模式文件他们之间的关系,那么如何将它们串联起来,供产品人员使用哪?下面咱们一步一步的实现
2、建立数据表
建表语句参考:http://www.cnblogs.com/liqiu/p/5202708.html
模式图如下:
这是一个典型的事实表+维度表的星型数据结构!
3、建立模式文件
这里就不说具体细节啦,直接给出xml文件内容,感兴趣的同学可以直接载入进去即可
<Schema name="SaleSchema">
<Cube name="SalesCube" visible="true" cache="true" enabled="true">
<Table name="sale" schema="public">
</Table>
<Dimension type="StandardDimension" visible="true" foreignKey="cusid" highCardinality="false" name="dimCustomer">
<Hierarchy visible="true" hasAll="true" allMemberName="allCustomer" primaryKey="cusid">
<Table name="customer" schema="public">
</Table>
<Level name="gender" visible="true" column="gender" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
<Dimension type="StandardDimension" visible="true" foreignKey="proid" highCardinality="false" name="dimProductType">
<Hierarchy visible="true" hasAll="true" allMemberName="allProduct" allMemberCaption="allProductTitle" primaryKey="proid" primaryKeyTable="product">
<Join leftKey="proid" rightKey="protypeid">
<Table name="product" schema="public">
</Table>
<Table name="producttype" schema="public">
</Table>
</Join>
<Level name="productId" visible="true" table="product" column="proid" nameColumn="proname" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
</Level>
<Level name="productTypeId" visible="true" table="producttype" column="protypeid" nameColumn="protypename" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
</Level>
</Hierarchy>
</Dimension>
<Measure name="saleNumber" column="num" aggregator="sum" caption="NumTitle" visible="true">
</Measure>
<Measure name="saleAmount" aggregator="sum" caption="allSaleTitle" visible="true">
<MeasureExpression>
<SQL dialect="generic">
<![CDATA[(unitprice*num)]]>
</SQL>
</MeasureExpression>
</Measure>
<CalculatedMember name="avgPrice" caption="avgPriceTitle" dimension="Measures" visible="true">
<Formula>
<![CDATA[[Measures].saleAmount/[Measures].saleNumber]]>
</Formula>
<CalculatedMemberProperty name="formatString" value="$#,##0.00">
</CalculatedMemberProperty>
</CalculatedMember>
</Cube>
</Schema>
4、查询数据
写如下MDX语句验证数据准确性
select
{[Measures].saleNumber,[Measures].saleAmount,[Measures].avgPrice}
on columns,
{([dimProductType].[allProduct],[dimCustomer].[allCustomer])}
on rows
from [salesCube]
结果如下:
5、上传模式文件
打开saiku,上传模式文件即可
如果如图: