Multiple metrics macro does not include results when dimension has NULL values
See original GitHub issueIs this a new bug in dbt_metrics?
- I believe this is a new bug in dbt_metrics
- I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
It looks like there is a issue when grouping metrics by dimensions with NULL values. I have a dimension that in certain case has NULL value, and when I use the macro for multiple metrics including this dimension the output does not include the rows where this dimension is NULL and the metric value is greater than zero.
Expected Behavior
In the output of the model, I would expect to have a row that include metrics value also when the dimension is NULL.
Steps To Reproduce
fix
Relevant log output
No response
Environment
- dbt-adapter & version:
- dbt_metrics version:
Which database adapter are you using with dbt?
snowflake
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Suppress the expressions with null value - Qlik Community
Hi Everyone, I have a question here. I created a Report Dimension, a Report Metric and a Virtual Dates which is also used...
Read more >dbt-labs/dbt_metrics: Macros for calculating metrics - GitHub
Multiple Metrics Note: The metrics must share the time_grain selected in the macro AND the dimensions selected in the macro. If these...
Read more >Do More with Null Values in Dimensions and Dates (Beta)
It's now easier to work with null value records in your datasets. When a record's dimension or date field is left blank, it...
Read more >SQL's NULL values: comparing, sorting, converting ... - SILOTA
The premise of NULL is to represent an unknown or missing value, though it's only a placeholder and not really a value by...
Read more >Query Syntax - Datadog Docs
It is not recommended to have spaces in trace attributes but in such cases, ... When there are multiple dimensions, the top values...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah - I see what you all mean. This is because the using clause is not a NULL-Safe operator, which means that it doesn’t match nulls. I’ll be completely honest - I am against changing the default join behavior to a Null-Safe operator because of the number of edge cases that it could cause to fail silently.
My suggested workaround would be to override NULL columns in the dimension in question in to some known quantity. It looks like
country
was provided as one of the dimensions included. I’d suggest altering the model this metric is built upon with the following logic:That should resolve your issue and ensure that the join logic remains consistent regardless of the behavior of the underlying columns.
Does that solution work for you both?
Because it’s already a widely used model across our warehouse, and our convention is generally that NULL means not set so changing the column would break with that convention. Basically changing the field would not be an option. Adding a new field would, but would feel like a hack.