-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds spark support for convert_timezone
- Loading branch information
1 parent
5f24102
commit dd2c5c2
Showing
1 changed file
with
14 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
{%- macro convert_timezone(column, target_tz=None, source_tz=None) -%} | ||
{%- set source_tz = "UTC" if not source_tz else source_tz -%} | ||
{%- set target_tz = var("dbt_date:time_zone") if not target_tz else target_tz -%} | ||
{{ adapter.dispatch('convert_timezone', packages = dbt_date._get_utils_namespaces()) (column, target_tz, source_tz) }} | ||
{%- endmacro -%} | ||
|
||
{% macro default__convert_timezone(column, target_tz, source_tz) -%} | ||
{%- if not source_tz -%} | ||
cast(convert_timezone('{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) | ||
{%- else -%} | ||
cast(convert_timezone('{{ source_tz }}', '{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) | ||
{%- endif -%} | ||
{%- if not source_tz -%} | ||
cast(convert_timezone('{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) | ||
{%- else -%} | ||
cast(convert_timezone('{{ source_tz }}', '{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
{%- macro bigquery__convert_timezone(column, target_tz, source_tz=None) -%} | ||
timestamp(datetime({{ column }}, '{{ target_tz}}')) | ||
timestamp(datetime({{ column }}, '{{ target_tz}}')) | ||
{%- endmacro -%} | ||
|
||
{%- macro spark__convert_timezone(column, target_tz, source_tz) -%} | ||
from_utc_timestamp( | ||
to_utc_timestamp({{ column }}, '{{ source_tz }}'), | ||
'{{ target_tz }}' | ||
) | ||
{%- endmacro -%} |