Skip to content

Commit

Permalink
fix: handle milliseconds in timestamp_from_parts for Databricks
Browse files Browse the repository at this point in the history
  • Loading branch information
silviustanimir authored and cverhoef committed Nov 13, 2023
1 parent 79f9b81 commit 764c005
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions macros/multiple_databases/timestamp_from_parts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@
{%- elif target.type == 'databricks' -%}
case
when length({{ date_field }}) > 0 and length({{ time_field }}) > 0
then timestamp_millis(bigint(bigint(unix_date({{ date_field }})) * 86400000) + unix_millis(try_to_timestamp({{ time_field }}, '{{ var("time_format", "HH:mm:ss[.SSS]") }}')))
else
to_timestamp(null)
then
case
when try_to_timestamp({{ time_field }}, '{{ var("time_format", "HH:mm:ss") }}.SSS') is null
then timestamp_millis(bigint(bigint(unix_date({{ date_field }})) * 86400000) + unix_millis(try_to_timestamp({{ time_field }}, '{{ var("time_format", "HH:mm:ss") }}')))
else timestamp_millis(bigint(bigint(unix_date({{ date_field }})) * 86400000) + unix_millis(try_to_timestamp({{ time_field }}, '{{ var("time_format", "HH:mm:ss") }}.SSS')))
end
else
to_timestamp(null)
end
{%- endif -%}

Expand Down

0 comments on commit 764c005

Please sign in to comment.