您的位置:首页 > 大数据 > 人工智能

结合使用saiku、mondrian workbentch建立多维查询报表

2016-02-21 22:03 387 查看
原文链接:https://www.geek-share.com/detail/2667063380.html

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,上传模式文件即可

如果如图:

 

转载于:https://www.cnblogs.com/liqiu/p/5205687.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐