saiku mondrian配置聚合表的目的是通过先生成要分析的数据,在实际分析时,直接从聚合表提取结果,省去实时分析的步骤,从而提高分析性能。
配置聚合表的方式:
<Cube name="Test_Demo">
<Table name="demo.t_test_demo" alias="t_test_demo">
<AggName name="agg_2_t_test_demo">
<AggFactCount column="row_count"/>
<AggMeasure name="[Measures].[UsersNum]" column="count_userid"/>
<AggMeasure name="[Measures].[CrashNum]" column="sum_crash_num"/>
<AggLevel name="[Isroot].[Isroot]" column="Isroot"/>
<AggLevel name="[Osversion].[Osversion]" column="Osversion"/>
</AggName>
</Table>
......
<Measure name="UsersNum" caption="用户数" column="userid" aggregator="count" datatype="Integer" />
<Measure name="CrashNum" caption="Crash数" column="crash_num" aggregator="sum" datatype="Integer" />
</cube>
聚合表的表结构定义如下:
create table agg_2_t_test_demo(
isroot string,
Osversion string,
count_userid bigint,
sum_crash_num bigint,
row_count bigint
);
更新完schemal后,重新装载时会报如下错误:
20:02:50,112 ERROR [AggTableManager] Recognizer.checkFactCount: Candidate aggregate table 'agg_2_t_test_demo' for fact table 't_test_demo' has no fact count columns.
20:02:50,112 ERROR [AggTableManager] Recognizer.checkNosMeasures: Candidate aggregate table 'agg_2_t_test_demo' for fact table 't_test_demo' has no measure columns.
出错原因及解决方法:
1、 <AggFactCount column="row_count"/> 这里的column必须是fact_count,这个是解决has no fact count columns的错误
2、 <AggMeasure name="[Measures].[UsersNum]" column="count_imei"/>
<AggMeasure name="[Measures].[CrashNum]" column="sum_crash_num"/>
这两配置的column必须和对应的Measures的column或是name相同才行,因此改成如下:
<AggMeasure name="[Measures].[UsersNum]" column="UsersNum"/>
<AggMeasure name="[Measures].[CrashNum]" column="CrashNum"/>
或
<AggMeasure name="[Measures].[UsersNum]" column="userid"/>
<AggMeasure name="[Measures].[CrashNum]" column="crash_num"/>
因此表定义改成如下:
create table agg_2_t_test_demo(
isroot string,
Osversion string,
userid bigint,
crash_num bigint,
fact_count bigint
);
改好后,重新装载schemal,saiku可以正常运行
注:
如果聚合表没有数据时,会自动检测出,并在日志中打出如下内容:
Zero size Aggregate table 'agg_2_t_test_demo' for Fact Table 't_test_demo'
这里,只要在聚合表中生成统计的数据即可