1、首先根据文档介绍,大致了解聚合表的概念:http://blog.linezing.com/?p=1448
2、根据聚合表名称规则建立聚合表(前提是已经有了可以使用的schema的cube,然后添加聚合表)
我的做法是先在schema中定义好聚合表的相关值,如:<cube name="cube_agent_state" caption="test" encoding="UTF-8"> <Table name="fact_agent_status_fact"> <AggName name="agg_c_fact_agent_status_fact" > <AggFactCount column="fact_count"/> <AggForeignKey factColumn="time_id" aggColumn="time_id" /> <AggForeignKey factColumn="agent_no" aggColumn="agent_no" /> <AggForeignKey factColumn="agent_status" aggColumn="agent_status" /> <AggForeignKey factColumn="reason_code" aggColumn="reason_code" /> <AggMeasure name="[Measures].[times]" column="times"/> <AggMeasure name="[Measures].[length]" column="length"/> </AggName> </Table> <Dimension name="times" foreignKey="time_id" caption="时间"> <Hierarchy hasAll="true" primaryKey="time_id" > <Table name="dim_date" /> <Level name="year" column="y_id" uniqueMembers="false" type="String" levelType="TimeYears" caption="年"/> <Level name="month" column="m_id" uniqueMembers="false" type="String" levelType="TimeMonths" caption="月"/> <Level name="week" column="w_b_id" uniqueMembers="false" type="String" levelType="TimeWeeks" caption="周"/> <Level name="day" column="d_id" uniqueMembers="false" type="String" levelType="TimeDays" caption="日"/> <Level name="minute" column="begin_time" uniqueMembers="false" type="String" levelType="TimeMinutes" caption="开始时间"/> </Hierarchy> </Dimension> <Dimension name="agent_nos" foreignKey="agent_no" caption="座席编号"> <Hierarchy hasAll="true" allMemberName="agent_no" primaryKey="no" primaryKeyTable="dim_agent"> <Table name="dim_agent" /> <Level name="agent_no" column="no" table="dim_agent" caption="座席编号"/> </Hierarchy> </Dimension> <Dimension name="agent_status" foreignKey="agent_status" caption="座席状态"> <Hierarchy hasAll="true" allMemberName="agent_status" primaryKey="agent_status" > <Table name="dim_agent_status" /> <Level name="agent_status_name" column="agent_status_name" uniqueMembers="false" levelType="Regular" type="String" caption="座席状态"/> </Hierarchy> </Dimension> <Dimension name="reason_code" foreignKey="reason_code" caption="小休类型" > <Hierarchy hasAll="true" allMemberName="reason_code" primaryKey="value" > <Table name="dim_dict" /> <Level name="reason_code_name" column="name" uniqueMembers="false" levelType="Regular" type="String" primaryKeyTable="dim_dict" caption="小休原因"/> </Hierarchy> </Dimension> <Measure name="length" column="length" aggregator="sum" formatString="#,###" datatype="Numeric" caption="总时长"/> <Measure name="times" column="id" aggregator="count" formatString="#,###" datatype="Numeric" caption="次数"/> </cube>
然后再建立聚合表
DROP TABLE IF EXISTS `agg_c_fact_agent_status`; CREATE TABLE `agg_c_fact_agent_status_fact` ( `fact_count` int(11) DEFAULT NULL, `time_id` varchar(50) DEFAULT NULL, `agent_no` varchar(20) DEFAULT NULL, `agent_status` int(1) DEFAULT NULL, `reason_code` char(1) DEFAULT NULL, `times` int(11) DEFAULT NULL, `length` int(11) DEFAULT NULL, `report_time` datetime DEFAULT NULL, KEY `i_fasf_time_id` (`time_id`), KEY `i_fasf_agent_no` (`agent_no`), KEY `i_fasf_agent_status` (`agent_status`), KEY `i_fasf_reason_code` (`reason_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
特别说明:AggMeasure 值是必须与原schema中定义的名称是相同的,如果measure是CalculatedMember类型,那么就不必要建立在聚合表中,否则会报错,在实际使用中,会自动使用因为这个是在Mondrian引擎中处理的,所以不需要处理
具体内容,还请参考如上示例,本文旨在帮助建立简单的schema,如果阅读过相关文档并了解过概念,理解本例子应该比较简单
by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/