Best Practice for Defining Composite Metrics Without Excessive Schema Overhead
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
**Problem**
Hi,
I’m looking for advice on the best way to define composite metrics based on existing metrics. For example, I want to define a new metric C as the sum of metrics A and B, and then be able to query metric C via a REST API.
Currently, I’m considering redefining a new metric C in the schema. However, this approach leads to an excessive number of schemas, which I’ve observed can decrease API query performance. Additionally, each new schema requires a recompilation process, which becomes more time-consuming as the number of schemas increases.
Is there a recommended approach to handle such composite metrics without the drawbacks of having too many schemas? How can I efficiently define and query composite metrics without negatively impacting performance and compile times?
Thank you for your insights!
**Related Cube.js schema**
```javascript
cube(`users`, {
sql_table: `users`,
measures: {
m_a: {
type: `sum`,
sql: `m_a`,
},
m_b: {
type: `sum`,
sql: `m_c`,
},
m_c: {
type: `sum`,
sql: `${m_a} + ${m_b}`,
},
},
dimensions: {
organization_id: {
sql: `organization_id`,
type: `number`,
primary_key: true,
},
created_at: {
sql: `created_at`,
type: `time`,
},
country: {
sql: `country`,
type: `string`,
},
},
});
```
Contributor guide
Assessment
This issue has not been assessed yet.