the error message for using dimensions within a non-aggregate metric isn't clear
See original GitHub issueHow I got here…
I tried to aggregate a dimension within a non-aggregate metric definition. This failed, because non-aggregate metrics can only take in other aggregate metrics.
^I think that this behaviour is fine: forcing people to write out metrics instead of doing dimension aggregations in the metric’s sql is pretty acceptable and makes it super clear what the restrictions of these non-aggregate metrics are. It’s also clearly explained in our docs that this is the behaviour to expect.
buuuuuut, it took me like 3 tries to figure out what was going wrong.
This was the yaml I had:
- name: email_campaign_id
description: The ID of the email campaign.
tests:
- unique
- not_null
meta:
metrics:
campaign_spam_report_rate:
description: "Spam report rate is the ratio of emails reported as spam out of the emails that were delivered."
type: number
sql: "(SUM(${total_unique_spam_reports}) / NULLIF(SUM(${total_unique_deliveries}), 0))"
This was the error I received:
This was the fix I needed to make:
- name: total_unique_spam_reports
meta:
metrics:
sum_of_total_unique_spam_reports:
type: sum
- name: total_unique_deliveries
meta:
metrics:
sum_of_total_unique_deliveries:
type: sum
- name: email_campaign_id
description: The ID of the email campaign.
tests:
- unique
- not_null
meta:
metrics:
campaign_spam_report_rate:
description: "Spam report rate is the ratio of emails reported as spam out of the emails that were delivered."
type: number
sql: "(${sum_of_total_unique_spam_reports}) / NULLIF(${sum_of_total_unique_deliveries}, 0)"
The error message should have a better description of what’s going wrong. Specifically, it should say something about the metric that’s erroring and the fact that it’s a non-aggregate metric. It should potentially link to the docs if that’s possible too!
e.g.
Error: `campaign_spam_report_rate` is a non-aggregate metric. It can only be defined using aggregate metrics, not dimensions. See the docs for how to build non-aggregate metrics: https://docs.lightdash.com/references/metrics#non-aggregate-metrics
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
Powerful error message @TuringLovesDeathMetal ! 🚀
Is this issue still relevant? There have been no updates for 60 days, please close the issue or keep the conversation going!