-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from dbt-labs/let-there-be-median
Let There Be Median
- Loading branch information
Showing
29 changed files
with
518 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Features | ||
body: Adding median | ||
time: 2023-01-09T14:55:30.09271-06:00 | ||
custom: | ||
Author: callum-mcdata | ||
Issue: "180" | ||
PR: "208" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
integration_tests/models/metric_definitions/base_median_metric.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version: 2 | ||
metrics: | ||
- name: base_median_metric | ||
model: ref('fact_orders') | ||
label: Total Discount ($) | ||
timestamp: order_date | ||
time_grains: [day, week, month, all_time] | ||
calculation_method: median | ||
expression: discount_total | ||
dimensions: | ||
- had_discount | ||
- order_country | ||
|
||
|
6 changes: 6 additions & 0 deletions
6
integration_tests/models/metric_testing_models/base_median_metric.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
select * | ||
from | ||
{{ metrics.calculate(metric('base_median_metric'), | ||
grain='month', | ||
dimensions=['had_discount']) | ||
}} |
4 changes: 4 additions & 0 deletions
4
integration_tests/models/metric_testing_models/base_median_metric_no_time_grain.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select * | ||
from | ||
{{ metrics.calculate(metric('base_median_metric')) | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
{% macro gen_calendar_table_join(metric_dictionary, calendar_tbl) %} | ||
{{ return(adapter.dispatch('gen_calendar_table_join', 'metrics')(metric_dictionary, calendar_tbl)) }} | ||
{% endmacro %} | ||
{%- endmacro -%} | ||
|
||
{% macro default__gen_calendar_table_join(metric_dictionary, calendar_tbl) %} | ||
|
||
left join {{calendar_tbl}} calendar_table | ||
{% if metric_dictionary.window is not none %} | ||
{%- if metric_dictionary.window is not none %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) > dateadd({{metric_dictionary.window.period}}, -{{metric_dictionary.window.count}}, calendar_table.date_day) | ||
and cast(base_model.{{metric_dictionary.timestamp}} as date) <= calendar_table.date_day | ||
{% else %} | ||
{%- else %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) = calendar_table.date_day | ||
{% endif %} | ||
|
||
{% endif -%} | ||
{% endmacro %} | ||
|
||
{% macro bigquery__gen_calendar_table_join(metric_dictionary, calendar_tbl) %} | ||
|
||
left join {{calendar_tbl}} calendar_table | ||
{% if metric_dictionary.window is not none %} | ||
{%- if metric_dictionary.window is not none %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) > date_sub(calendar_table.date_day, interval {{metric_dictionary.window.count}} {{metric_dictionary.window.period}}) | ||
and cast(base_model.{{metric_dictionary.timestamp}} as date) <= calendar_table.date_day | ||
{% else %} | ||
{%- else %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) = calendar_table.date_day | ||
{% endif %} | ||
|
||
{% endif -%} | ||
{% endmacro %} | ||
|
||
{% macro postgres__gen_calendar_table_join(metric_dictionary, calendar_tbl) %} | ||
|
||
left join {{calendar_tbl}} calendar_table | ||
{% if metric_dictionary.window is not none %} | ||
{%- if metric_dictionary.window is not none %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) > calendar_table.date_day - interval '{{metric_dictionary.window.count}} {{metric_dictionary.window.period}}' | ||
and cast(base_model.{{metric_dictionary.timestamp}} as date) <= calendar_table.date_day | ||
{% else %} | ||
{%- else %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) = calendar_table.date_day | ||
{% endif %} | ||
|
||
{% endif -%} | ||
{% endmacro %} | ||
|
||
{% macro redshift__gen_calendar_table_join(metric_dictionary, calendar_tbl) %} | ||
|
||
left join {{calendar_tbl}} calendar_table | ||
{% if metric_dictionary.window is not none %} | ||
{%- if metric_dictionary.window is not none %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) > dateadd({{metric_dictionary.window.period}}, -{{metric_dictionary.window.count}}, calendar_table.date_day) | ||
and cast(base_model.{{metric_dictionary.timestamp}} as date) <= calendar_table.date_day | ||
{% else %} | ||
{%- else %} | ||
on cast(base_model.{{metric_dictionary.timestamp}} as date) = calendar_table.date_day | ||
{% endif %} | ||
|
||
{% endif -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.