cube.js measures 的一些说明
以前有介绍过关于cube.js 的measures,以下主要说明一些新的特性
filter
主要进行一个计算的过滤处理
ordersCompletedCount: {
sql: `id`,
type: `count`,
filters: [
{ sql: `${CUBE}.status = 'completed'` }
]
}
生成的参考类似sql
SELECT
count(
CASE
WHEN ("caseapp".type = 'v1') THEN "caseapp".type
END
) "caseapp__v1app"
FROM
demoapp AS "caseapp"
LIMIT
10000
计算指标
purchasesToCreatedAccountRatio: {
sql: `${purchases} / ${Users.count} * 100.0`,
type: `number`,
format: `percent`
}
drillMembers
支持数据的钻取处理,对于使用我们需要,多次调用(可以基于api)
revenue: {
type: `sum`,
sql: `price`,
drillMembers: [id, price, status, Products.name, Products.id]
}
参考资料
https://cube.dev/docs/measures
https://cube.dev/blog/introducing-a-drill-down-table-api-in-cubejs/
https://cube.dev/docs/@cubejs-client-core#result-set-drill-down