-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
get_base_dates.sql
91 lines (69 loc) · 2.35 KB
/
get_base_dates.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart="day") %}
{{ adapter.dispatch('get_base_dates', 'dbt_date') (start_date, end_date, n_dateparts, datepart) }}
{% endmacro %}
{% macro default__get_base_dates(start_date, end_date, n_dateparts, datepart) %}
{%- if start_date and end_date -%}
{%- set start_date="cast('" ~ start_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}
{%- set end_date="cast('" ~ end_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}
{%- elif n_dateparts and datepart -%}
{%- set start_date = dbt.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set end_date = dbt_date.tomorrow() -%}
{%- endif -%}
with date_spine as
(
{{ dbt_date.date_spine(
datepart=datepart,
start_date=start_date,
end_date=end_date,
)
}}
)
select
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
from
date_spine d
{% endmacro %}
{% macro bigquery__get_base_dates(start_date, end_date, n_dateparts, datepart) %}
{%- if start_date and end_date -%}
{%- set start_date="cast('" ~ start_date ~ "' as datetime )" -%}
{%- set end_date="cast('" ~ end_date ~ "' as datetime )" -%}
{%- elif n_dateparts and datepart -%}
{%- set start_date = dbt.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set end_date = dbt_date.tomorrow() -%}
{%- endif -%}
with date_spine as
(
{{ dbt_date.date_spine(
datepart=datepart,
start_date=start_date,
end_date=end_date,
)
}}
)
select
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
from
date_spine d
{% endmacro %}
{% macro trino__get_base_dates(start_date, end_date, n_dateparts, datepart) %}
{%- if start_date and end_date -%}
{%- set start_date="cast('" ~ start_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}
{%- set end_date="cast('" ~ end_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}
{%- elif n_dateparts and datepart -%}
{%- set start_date = dbt.dateadd(datepart, -1 * n_dateparts, dbt_date.now()) -%}
{%- set end_date = dbt_date.tomorrow() -%}
{%- endif -%}
with date_spine as
(
{{ dbt_date.date_spine(
datepart=datepart,
start_date=start_date,
end_date=end_date,
)
}}
)
select
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
from
date_spine d
{% endmacro %}