From 92a1951e102bb4276feea8d370f78a67face7d3f Mon Sep 17 00:00:00 2001 From: Vasilii Surov Date: Fri, 2 Apr 2021 21:01:31 -0400 Subject: [PATCH 1/3] Issue 16 in BQ date should be compared to date --- macros/get_base_dates.sql | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/macros/get_base_dates.sql b/macros/get_base_dates.sql index 5d2d6b3..cafc7b9 100644 --- a/macros/get_base_dates.sql +++ b/macros/get_base_dates.sql @@ -1,4 +1,8 @@ {% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} + {{ adapter.dispatch('get_base_dates', packages = dbt_date._get_utils_namespaces()) (start_date, end_date) }} +{% endmacro %} + +{% macro default__get_base_dates(start_date, end_date) %} with date_spine as ( {% if start_date and end_date %} @@ -23,4 +27,31 @@ select cast(d.date_day as date) as date_day from date_spine d -{% endmacro %} \ No newline at end of file +{% endmacro %} + +{% macro bigquery__get_base_dates(start_date, end_date) %} +with date_spine as +( + {% if start_date and end_date %} + {%- set start_date="cast('" ~ start_date ~ "' as date )" -%} + {%- set end_date="cast('" ~ end_date ~ "' as date )" -%} + + {% elif n_dateparts and datepart %} + + {%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} + {%- set end_date = dbt_date.tomorrow() -%} + {% endif %} + + {{ dbt_utils.date_spine( + datepart="day", + start_date=start_date, + end_date=end_date, + ) + }} + +) +select + cast(d.date_day as date) as date_day +from + date_spine d +{% endmacro %} From e0efa7b9eb5eea7eaed3dbd4397d64ab1b984e69 Mon Sep 17 00:00:00 2001 From: Vasilii Surov Date: Fri, 2 Apr 2021 21:01:31 -0400 Subject: [PATCH 2/3] Issue 16 in BQ date should be compared to date --- macros/get_base_dates.sql | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/macros/get_base_dates.sql b/macros/get_base_dates.sql index 5d2d6b3..fd7bbce 100644 --- a/macros/get_base_dates.sql +++ b/macros/get_base_dates.sql @@ -1,4 +1,8 @@ {% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} + {{ adapter.dispatch('get_base_dates', packages = dbt_date._get_utils_namespaces()) (start_date, end_date, n_dateparts, datepart) }} +{% endmacro %} + +{% macro default__get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} with date_spine as ( {% if start_date and end_date %} @@ -23,4 +27,31 @@ select cast(d.date_day as date) as date_day from date_spine d -{% endmacro %} \ No newline at end of file +{% endmacro %} + +{% macro bigquery__get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} +with date_spine as +( + {% if start_date and end_date %} + {%- set start_date="cast('" ~ start_date ~ "' as date )" -%} + {%- set end_date="cast('" ~ end_date ~ "' as date )" -%} + + {% elif n_dateparts and datepart %} + + {%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} + {%- set end_date = dbt_date.tomorrow() -%} + {% endif %} + + {{ dbt_utils.date_spine( + datepart="day", + start_date=start_date, + end_date=end_date, + ) + }} + +) +select + cast(d.date_day as date) as date_day +from + date_spine d +{% endmacro %} From 64206d07a69a37b045ba23b13b2bab582cfa3735 Mon Sep 17 00:00:00 2001 From: Vasilii Surov Date: Fri, 2 Apr 2021 21:01:31 -0400 Subject: [PATCH 3/3] Issue 16 in BQ date should be compared to date --- macros/get_base_dates.sql | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/macros/get_base_dates.sql b/macros/get_base_dates.sql index 5d2d6b3..aefca79 100644 --- a/macros/get_base_dates.sql +++ b/macros/get_base_dates.sql @@ -1,4 +1,8 @@ {% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %} + {{ adapter.dispatch('get_base_dates', packages = dbt_date._get_utils_namespaces()) (start_date, end_date, n_dateparts, datepart) }} +{% endmacro %} + +{% macro default__get_base_dates(start_date, end_date, n_dateparts, datepart) %} with date_spine as ( {% if start_date and end_date %} @@ -23,4 +27,31 @@ select cast(d.date_day as date) as date_day from date_spine d -{% endmacro %} \ No newline at end of file +{% endmacro %} + +{% macro bigquery__get_base_dates(start_date, end_date, n_dateparts, datepart) %} +with date_spine as +( + {% if start_date and end_date %} + {%- set start_date="cast('" ~ start_date ~ "' as date )" -%} + {%- set end_date="cast('" ~ end_date ~ "' as date )" -%} + + {% elif n_dateparts and datepart %} + + {%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} + {%- set end_date = dbt_date.tomorrow() -%} + {% endif %} + + {{ dbt_utils.date_spine( + datepart="day", + start_date=start_date, + end_date=end_date, + ) + }} + +) +select + cast(d.date_day as date) as date_day +from + date_spine d +{% endmacro %}