-
Notifications
You must be signed in to change notification settings - Fork 47
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
Let there be all time #99
Conversation
This looks OK to me so far -- only real comment is that for an select * from
-- depends on: development.dbt_dconnors.dbt_metrics_default_calendar
(
-- this CTE isn't used at all
with calendar as (
select
*
from development.dbt_dconnors.dbt_metrics_default_calendar
where date_day >= cast('2022-05-01' as date)
and date_day <= cast('2022-06-01' as date)
)
, total_value__aggregate as (
select
sum(property_to_aggregate) as total_value,
min(metric_date_day) as metric_start_date,
max(metric_date_day) as metric_end_date
from (
...
I imagine this was to simplify the comma situation for where the metric aggregate CTE shows up and given that it's such a simple small table i'm guessing there's not really any performance concern at all |
100% this is the main reason - adding conditional logic to handle the first cte with all the options would be a massive pain. But additionally, we also want to support the use of |
@joellabes would love to get your 2c here. Generally this keeps to the same framework but it definitely adds some more conditional logic into the macros to account for different behavior. That being said, I think it does so in a way that keeps the macros from trying to do too many things (such as two different paths). By and large it just alters the columns/joins |
What is this PR?
This is a:
All pull requests from community contributors should target the
main
branch (default).Description & motivation
Right now, the metrics package will always return a date spined result set that shows the metric over a length of time. But what if the user just wants a single number? For that, we've added
all_time
as an acceptable input for all metric types. This produces a dataset that is not date spined but instead corresponds to the lifetime of value included in the macro call.IE - if a user designates
start_date
andend_date
and then usesall_time
as the grain, it will return the value of the metric in that time period.For cleanliness and ease of understanding, we've included
metric_start_date
andmetric_end_date
in the returned dataset.Example output - no dimensions
Example output - with dimensions
Important Changes
secondary_calculations
tovalidate_grain
. This checks to make sure that there are nosecondary_calculations
provided if the grain isall_time
, as those are not supported.build_metric_sql
to not rungen_dimensions_cte
orgen_spine_time_cte
if the grain isall_time
gen_aggregate_cte
to not add any date fields (such as date_day) to the grouping if the grain isall_time
gen_aggregate_cte
to includemetric_start_date
andmetric_end_date
if the grain isall_time
gen_group_by
to support the date field now being an optional input.gen
macros to not include the date field.using
statement ingen_joined_metrics_cte
now that there are conditions in which there would be no fields provided. For those ones, we switch from using a left outer join to a cross join.gen_metric_cte
toparent_metric_cte
to make it easier to reference fieldsChecklist
Tenets to keep in mind