Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion macros/date_add_cross_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{{ date_column }} + interval '{{ days }} days'
{% elif target.type == 'bigquery' %}
date_add({{ date_column }}, interval {{ days }} day)
{% elif target.type == 'snowflake' %}
dateadd(day, {{ days }}, {{ date_column }})
{% else %}
{{ date_column }} + interval {{ days }} day
{{ exceptions.raise_compiler_error("Unsupported database type: " ~ target.type) }}
{% endif %}
{% endmacro %}
11 changes: 11 additions & 0 deletions macros/date_diff_cross_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% macro date_diff_cross_db(end_date, start_date, unit) %}
{% if target.type == 'bigquery' %}
date_diff({{ end_date }}, {{ start_date }}, {{ unit }})
{% elif target.type == 'postgres' %}
extract(epoch from ({{ end_date }} - {{ start_date }})) / 86400
{% elif target.type == 'snowflake' %}
datediff({{ unit }}, {{ start_date }}, {{ end_date }})
{% else %}
{{ exceptions.raise_compiler_error("Unsupported database type: " ~ target.type) }}
{% endif %}
{% endmacro %}
2 changes: 2 additions & 0 deletions macros/quarter_end_date.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
DATE_ADD(DATE_ADD({{ quarter_start_column }}, INTERVAL 3 MONTH), INTERVAL -1 DAY)
{% elif target.type == 'postgres' %}
({{ quarter_start_column }} + INTERVAL '3 months' - INTERVAL '1 day')::date
{% elif target.type == 'snowflake' %}
DATEADD(DAY, -1, DATEADD(MONTH, 3, {{ quarter_start_column }}))
{% else %}
{{ exceptions.raise_compiler_error("Unsupported database type: " ~ target.type) }}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion models/demo/deals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ select
-- this code keeps the date fields relevant for the demo environment
-- it adds the difference between the current date and a fixed date (2025-01-01)
-- to the original date fields, effectively shifting them into the future
{{ date_add_cross_db('created_date', 'date_diff(current_date(), \'2025-01-01\', day)') }} as created_date
{{ date_add_cross_db('created_date', date_diff_cross_db('current_date()', '\'2025-01-01\'', 'day')) }} as created_date
from
{{ ref('deals_raw') }}
2 changes: 1 addition & 1 deletion models/demo/tracks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ select
-- this code keeps the date fields relevant for the demo environment
-- it adds the difference between the current date and a fixed date (2025-01-01)
-- to the original date fields, effectively shifting them into the future
{{ date_add_cross_db('t.event_timestamp', 'date_diff(current_date(), \'2025-01-01\', day)') }} as timestamp
{{ date_add_cross_db('t.event_timestamp', date_diff_cross_db('current_date()', '\'2025-01-01\'', 'day')) }} as timestamp
from
{{ ref('tracks_raw') }} t

Expand Down
6 changes: 3 additions & 3 deletions models/demo/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ select
-- this code keeps the date fields relevant for the demo environment
-- it adds the difference between the current date and a fixed date (2025-01-01)
-- to the original date fields, effectively shifting them into the future
{{ date_add_cross_db('created_at', 'date_diff(current_date(), \'2025-01-01\', day)') }} as created_at,
{{ date_add_cross_db('first_logged_in_at', 'date_diff(current_date(), \'2025-01-01\', day)') }} as first_logged_in_at,
{{ date_add_cross_db('latest_logged_in_at', 'date_diff(current_date(), \'2025-01-01\', day)') }} as latest_logged_in_at
{{ date_add_cross_db('created_at', date_diff_cross_db('current_date()', '\'2025-01-01\'', 'day')) }} as created_at,
{{ date_add_cross_db('first_logged_in_at', date_diff_cross_db('current_date()', '\'2025-01-01\'', 'day')) }} as first_logged_in_at,
{{ date_add_cross_db('latest_logged_in_at', date_diff_cross_db('current_date()', '\'2025-01-01\'', 'day')) }} as latest_logged_in_at
from
cleaned_data