解决Mondrian 创建时间维度Hours的难题

最近一直忙于熟悉Mondrian,其中也遇到了一下问题

 

其中一个比较麻烦的就是这样的

 

我们的时间维度里面包含有Year、Quarter、Month、Day、Hour

 

其中前面几个是可以正常的钻取的(Year、Quarter、Month、Day)

 

但是当从Day 2011-07-5 钻取到Hours的时候就出了问题,数据只出来一条并且是 2011-07-05  00:00:00。

 

看看数据库中的Hours这个字段是Date类型的,而生成的MDX语句如下:


select "DIM_PUB_HOUR"."HOUR" as "c0" from "DIM_PUB_HOUR" "DIM_PUB_HOUR"
where ("DIM_PUB_HOUR"."DAY" = DATE '2011-06-08' and "DIM_PUB_HOUR"."MONTH" = '2011-06' and "DIM_PUB_HOUR"."YEAR" = '2011')
and "DIM_PUB_HOUR"."HOUR" = DATE '2011-06-08' group by "DIM_PUB_HOUR"."HOUR" order by "DIM_PUB_HOUR"."HOUR" ASC

 

<Cube name="&#20449;&#21495;&#26426;&#27969;&#37327;&#20998;&#26512;" cache="true" enabled="true">
    <Table name="FACT_CLL_XHJ">
    </Table>
    <Dimension type="StandardDimension" foreignKey="DEV" highCardinality="false" name="RoadNum" caption="&#36335;&#21475;&#32534;&#21495;">
      <Hierarchy name="&#36335;&#21475;&#32534;&#21495;" hasAll="true" allMemberName="&#25152;&#26377;&#36335;&#21475;" primaryKey="BH">
        <Table name="DIM_CLL_DEV">
        </Table>
        <Level name="RoadNum" column="NAME" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="TimeDimension" foreignKey="TIME_ID" highCardinality="false" name="TimePoint" caption="&#26102;&#38388;&#28857;">
      <Hierarchy name="&#26102;&#38388;" hasAll="true" allMemberName="&#25152;&#26377;&#26102;&#38388;" primaryKey="XH">
        <Table name="DIM_PUB_HOUR">
        </Table>
        <Level name="Year" column="YEAR" type="String" uniqueMembers="true" levelType="TimeYears" hideMemberIf="Never">
        </Level>
        <Level name="Month" column="MONTH" nameColumn="MONTH_NAME" type="String" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never">
        </Level>
        <Level name="Day" column="DAY" type="Date" uniqueMembers="false" levelType="TimeDays" hideMemberIf="Never">
        </Level>
        <Level name="Hours" column="HOURS"  uniqueMembers="false" levelType="TimeHours" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="StandardDimension" foreignKey="WAY" highCardinality="false" name="CarRoadNum" caption="&#36710;&#36947;&#32534;&#21495;">
      <Hierarchy name="&#36710;&#36947;&#32534;&#21495;" hasAll="true" allMemberName="&#25152;&#26377;&#36710;&#36947;&#32534;&#21495;" primaryKey="BH">
        <Table name="DIM_CLL_WAY">
        </Table>
        <Level name="CarRoadNum" column="BH" type="String" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
        </Level>
      </Hierarchy>
    </Dimension>
    <Measure name="&#27969;&#36890;&#37327;" column="CLL" aggregator="sum" visible="true">
    </Measure>
    <CalculatedMember name="FlowCount" caption="&#27969;&#36890;&#37327;&#35745;&#31639;" formula="sum([Measures].[&#27969;&#36890;&#37327;])" dimension="Measures" visible="true">
    </CalculatedMember>
  </Cube>

 

很明显上面只执行了一个查询 0 点时候的数据,其他小时都没有查询,去网上查了一下。

才知道Mondriad暂时对这个小时还不支持。解决办法:

 

1.把数据库所有时间维类型都改成numeric类型的,把他们当做普通的维度来做

 

2.在表中新增一个字段 Hours_name 是 numeric  其中的值为 0-23 ,然后 用

 

 <Level name="Hours" column="HOUR_NAME" type="Numeric" uniqueMembers="false" levelType="TimeHours" hideMemberIf="Never">
        </Level>

这样就可以正常的使用了。

你可能感兴趣的:(mondrian)