我正在尝试创建一个指示器,它是下订单的客户的不同计数。蒙德里安模式的相关部分如下:
<Measure name="Active Customers" formatString="#" aggregator="distinct-count">
<MeasureExpression>
<SQL dialect="mysql">
CASE WHEN <Column name ='placed_count'/> > 0 THEN 1 END
</SQL>
</MeasureExpression>
</Measure>
由于某些原因,列名不会被其列名(包括表别名)替换。我可以在日志中查看:
Caused by: mondrian.olap.MondrianException: Mondrian Error:Internal error: Error while loading segment; sql=[select `v_dm_calendar`.`calendar_date` as `c0`, count(distinct CASE WHEN > 0 THEN 1 END) as `m0` from `v_dm_calendar` as `v_dm_calendar`, `fc_customer_activity_sportsbook` as `fc_customer_activity_sportsbook` where `fc_customer_activity_sportsbook`.`bet_date` = `v_dm_calendar`.`calendar_date` and `v_dm_calendar`.`calendar_date` = '2015-03-30' group by `v_dm_calendar`.`calendar_date`]
at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:972)
at mondrian.olap.Util.newInternal(Util.java:2404)
at mondrian.olap.Util.newError(Util.java:2420)
at mondrian.rolap.SqlStatement.handle(SqlStatement.java:353)
at mondrian.rolap.SqlStatement.execute(SqlStatement.java:253)
at mondrian.rolap.RolapUtil.executeQuery(RolapUtil.java:350)
at mondrian.rolap.agg.SegmentLoader.createExecuteSql(SegmentLoader.java:625)
... 8 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '> 0 THEN 1 END) as `m0` from `v_dm_calendar` as `v_dm_calendar`, `fc_customer_ac' at line 1
我在语法上遗漏了什么吗?我在官方文件和蒙德里安的书中都找不到任何东西。
最佳答案
它在蒙德里安3中的定义如下:
<MeasureExpression>
<SQL dialect="generic">
<![CDATA[case when placed_count > 0 then 1 else 0 end]]>
</SQL>
</MeasureExpression>
在Mondrian 4中,您需要将
calculated column
添加到事实表的声明中,并创建一个measure based upon it
:<Table name="??">
<ColumnDefs>
<CalculatedColumnDef name="active_customers">
<ExpressionView>
<SQL dialect="generic">
(case when <Column name="placed_count"/> >
0 then 1 end)
</SQL>
</ExpressionView>
</CalculatedColumnDef>
</ColumnDefs>
</Table>
<Measure name="Active Customers" aggregator="distinct-count" column="active_customers" formatString="#">
有关更多信息,请比较Mondrian 4和Mondrian 3文档中的
3.2 Measures
部分。