Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best Practice for Defining Composite Metrics Without Excessive Schema Overhead #8686

Open
w1992wishes opened this issue Sep 10, 2024 · 0 comments
Labels
question The issue is a question. Please use Stack Overflow for questions.

Comments

@w1992wishes
Copy link

w1992wishes commented Sep 10, 2024

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

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`,
    },
  },
});
@w1992wishes w1992wishes added the question The issue is a question. Please use Stack Overflow for questions. label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a question. Please use Stack Overflow for questions.
Projects
None yet
Development

No branches or pull requests

1 participant