简体   繁体   中英

Pentaho Mondrian using aggregate tables

I have xml schema description for Pentaho Mondrian. It looks like this:

    <Dimension foreignKey="dt" name="dt" type="TimeDimension">
    <Hierarchy allMemberName="All" hasAll="true" name="Hierarchy" primaryKey="dt" visible="true">
    <View alias="dt_view">
    <SQL dialect="generic">select distinct "dt",date_part('year', "dt")::integer AS year, date_part('month', "dt")::integer AS month, date_part('day', "dt")::integer AS day from "world_steel_production"."world_steel_production_data"
    </SQL>
    </View>
    <Level captionColumn="year" column="year" hideMemberIf="Never" levelType="TimeYears" name="Years" type="Integer" uniqueMembers="false"/>
    <Level column="month" formatter="capsidea.MemberMonthFormatter" hideMemberIf="Never" levelType="TimeMonths" name="Month" type="Integer" uniqueMembers="false"/>
    </Hierarchy>
    </Dimension>

    <Dimension foreignKey="obj" name="Index">
    <Hierarchy allMemberName="All" hasAll="true" name="name_ru" primaryKey="key" visible="true">
    <Table name="world_steel_production_dict_obj" schema="world_steel_production"/>
    <Level column="key" nameColumn="name_ru" parentColumn="parent_key" hideMemberIf="Never" levelType="Regular" name="Level" type="Integer" uniqueMembers="true"/>
    </Hierarchy>
    </Dimension>

    <Measure aggregator="sum" column="vl" name="Value" visible="true"/>

</Cube>

Our timedimension <Dimension foreignKey="dt" name="dt" type="TimeDimension"> contains two levels: "year" and "month" When I choose level "year" Mondrian aggregates data by year.

It seems fine, but table world_steel_production_data has two dynamic levels in data which defines columns dl (1 - year dynamic and 4 - month dynamic)

在此处输入图片说明

This case when I aggregate data by year level in 1980 contains data with year and month dynamics.

I've read ( http://mondrian.pentaho.com/documentation/aggregate_tables.php ) that Pentaho can use aggregate table and I want to use them in order to split my month and year dynamics.

I've create two vies for aggregate table purpose

create or replace view world_steel_production.world_steel_production_data_view_year
as 
select *
from world_steel_production.world_steel_production_data
where dl = 1

and

create or replace view world_steel_production.world_steel_production_data_view_month
as 
select *
from world_steel_production.world_steel_production_data
where dl = 4

But now I'm wandering how to say to Pentaho in my xml schema definition use the first view for year dynamics and second one for month dynamics?

Or maybe there is another way to split year and months dynamics?

I think I've found the solution. Mondrian has such thing as Closure tables ( http://mondrian.pentaho.com/documentation/schema.php#Closure_tables ). At this table you can define how to aggregate in your hierarchy dimension.

What I've done in my situation:

  1. I've created and filled hierarchy table for dates and link this table with data-table in my schema.

在此处输入图片说明

  1. Next I've created and filled closure table.

在此处输入图片说明

As you can see, I've filled closure table as my world_steel_production_time_hierarchy has no hierarchy at all (time_id = parent_time_id).

  1. And at last I've changed XML data definition.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM