Cube
2023-09-18 23:21:56 5 举报
AI智能生成
Cube 文档(https://cube.dev/docs/) 阅读笔记
作者其他创作
大纲/内容
核心功能
Data modeling 数据模型
Cubes 多维数据集
类似于 SQL 中的视图
使用方式
数据库单个表
cube(`orders`, {
sql_table: `orders`
});
sql_table: `orders`
});
SQL
cube(`orders`, {
sql: `
SELECT *
FROM orders, line_items
WHERE orders.id = line_items.order_id
`
});
sql: `
SELECT *
FROM orders, line_items
WHERE orders.id = line_items.order_id
`
});
Demensions 维度
cube(`orders`, {
// ...
dimensions: {
id: {
sql: `id`,
type: `number`,
// Here we explicitly let Cube know this field is the primary key
// This is required for de-duplicating results when using joins
primary_key: true,
},
status: {
sql: `status`,
type: `string`,
},
},
});
// ...
dimensions: {
id: {
sql: `id`,
type: `number`,
// Here we explicitly let Cube know this field is the primary key
// This is required for de-duplicating results when using joins
primary_key: true,
},
status: {
sql: `status`,
type: `string`,
},
},
});
多维数据集中单个数据点的属性
Measures 度量
cube(`orders`, {
// ...
measures: {
count: {
type: `count`,
},
},
});
// ...
measures: {
count: {
type: `count`,
},
},
});
多维数据集中一组数据点的属性
Joins 表关联
cube(`orders`, {
// ...
joins: {
line_items: {
relationship: `many_to_one`,
// Here we use the `CUBE` global to refer to the current cube,
// so the following is equivalent to `orders.id = line_items.order_id`
sql: `${CUBE}.id = ${line_items.order_id}`,
},
},
});
// ...
joins: {
line_items: {
relationship: `many_to_one`,
// Here we use the `CUBE` global to refer to the current cube,
// so the following is equivalent to `orders.id = line_items.order_id`
sql: `${CUBE}.id = ${line_items.order_id}`,
},
},
});
多维数据集之间的关系
Cube 中有连接默认都是左连接
三种连接关系
一对一
one_to_one
一对多
one_to_many
多对一
many_to_one
Segments 数据模型过滤器
cube(`orders`, {
// ...
segments: {
only_completed: {
sql: `${CUBE}.status = 'completed'`,
},
},
});
// ...
segments: {
only_completed: {
sql: `${CUBE}.status = 'completed'`,
},
},
});
数据模型中预定义的过滤器
不是 Cube 查询,允许简化 Cube 查询,并使得跨各种查询重用通用过滤器变得容易
Pre-aggregaions 预聚合
cube(`orders`, {
// ...
pre_aggregations: {
main: {
measures: [CUBE.count],
dimensions: [CUBE.status],
timeDimension: CUBE.created_at,
granularity: `day`,
},
},
});
// ...
pre_aggregations: {
main: {
measures: [CUBE.count],
dimensions: [CUBE.status],
timeDimension: CUBE.created_at,
granularity: `day`,
},
},
});
缓存指定组合查询条件结果
其他
Drilldowns 数据钻取
Introducing a Drill Down Table API in Cube.js
Subquery 子查询
String time dimensions 字符串时间维度
可对时间进行格式化
滑动窗口 rolling window
必须要给出一个 date range
0 条评论
下一页