cube.js data Blending
cube.js 的 data Blending,主要是解决多数据schema 数据集成(数据charts的集成)的问题
官方的解决方法还是比较简单的,核心是使用了sql 的union all 同时引用了数据schema 的sql
同时cube.js 也提供了多查询的处理,会自己进行转换处理
参考
- 数据schema
cube(`AllSales`, {
sql: `
select amount, user_id as customer_id, created_at, 'Transactions' row_type from ${Transactions.sql()}
UNION ALL
select amount, customer_id, created_at, 'Orders' row_type from ${Orders.sql()}
`,
measures: {
customerCount: {
sql: `customer_id`,
type: `countDistinct`
},
revenue: {
sql: `amount`,
type: `sum`
},
onlineRevenue: {
sql: `amount`,
type: `sum`,
filters: [{ sql: `${CUBE}.row_type = 'Transactions'` }]
},
offlineRevenue: {
sql: `amount`,
type: `sum`,
filters: [{ sql: `${CUBE}.row_type = 'Orders'` }]
},
onlineRevenuePercentage: {
sql: `${onlineRevenue} / NULLIF(${onlineRevenue} + ${offlineRevenue}, 0)`,
type: `number`,
format: `percent`
}
},
dimensions: {
createdAt: {
sql: `created_at`,
type: `time`
},
revenueType: {
sql: `row_type`,
type: `string`
}
}
});
- api 查询
import cubejs from '@cubejs-client/core';
const API_URL = 'http://localhost:4000';
const CUBEJS_TOKEN = 'YOUR_TOKEN';
const cubejsApi = cubejs(CUBEJS_TOKEN, {
apiUrl: `${API_URL}/cubejs-api/v1`
});
const queries = [
{
measures: ['Transactions.revenue'],
timeDimensions: [
{
dimension: 'Transactions.createdAt',
granularity: 'day',
dateRange: ['2020-08-01', '2020-08-07']
}
]
},
{
measures: ['Orders.revenue'],
timeDimensions: [
{
dimension: 'Orders.createdAt',
granularity: 'day',
dateRange: ['2020-08-01', '2020-08-07']
}
]
}
];
const resultSet = await cubejsApi.load(queries);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2020-01-01 Quark 基于electron 的跨平台应用开发ide
2020-01-01 nodejs 应用火焰图简单分析
2019-01-01 Gravitee.io api gateway 试用
2017-01-01 netflix:Conductor微服务编排引擎