Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
silviustanimir committed Nov 14, 2023
1 parent d8fea96 commit 8b201c4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions macros/multiple_databases/dateadd.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
{%- elif target.type == 'sqlserver' -%}
dateadd({{ datepart }}, {{ number }}, try_convert(datetime2, {{ datetime_field }}))
{%- elif target.type == 'databricks' -%}
{%- set clock_component -%}
to_unix_timestamp({{ datetime_field }}) - to_unix_timestamp(date_trunc('DD', {{ datetime_field }}))
{%- endset -%}
{%- if datepart == 'second' -%}
timestamp_millis(bigint(unix_millis({{ datetime_field }}) + {{ number }}*1000))
try_to_timestamp(to_unix_timestamp({{ datetime_field }}) + {{ number }})
{%- elif datepart == 'minute' -%}
timestamp_millis(bigint(unix_millis({{ datetime_field }}) + {{ number }}*6000))
try_to_timestamp(to_unix_timestamp({{ datetime_field }}) + {{ number }}*60)
{%- elif datepart == 'hour' -%}
timestamp_millis(bigint(unix_millis({{ datetime_field }}) + {{ number }}*3600000))
try_to_timestamp(to_unix_timestamp({{ datetime_field }}) + {{ number }}*3600)
{%- elif datepart == 'day' -%}
timestamp_millis(bigint(unix_millis({{ datetime_field }}) + {{ number }}*86400000))
try_to_timestamp(to_unix_timestamp(date_add({{ datetime_field }}, {{ number }})) + {{ clock_component }})
{%- elif datepart == 'year' -%}
timestamp_millis(bigint(add_months({{ datetime_field }}, {{ number }}*12) + bigint(unix_millis({{ datetime_field }})) - bigint(unix_millis(date_trunc('DD', {{ datetime_field }})))))
try_to_timestamp(to_unix_timestamp(add_months({{ datetime_field }}, {{ number }}*12)) + {{ clock_component }})
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

0 comments on commit 8b201c4

Please sign in to comment.