Skip to content

Commit

Permalink
Merge pull request #17 from VasiliiSurov/main
Browse files Browse the repository at this point in the history
Issue 16 in BQ date should be compared to date
  • Loading branch information
clausherther authored Apr 3, 2021
2 parents cb1a934 + 97ef9e1 commit e58387d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion macros/get_base_dates.sql
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -23,4 +27,31 @@ select
cast(d.date_day as date) as date_day
from
date_spine d
{% endmacro %}
{% 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 %}

0 comments on commit e58387d

Please sign in to comment.