-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance formatting of function macros
- Loading branch information
Showing
8 changed files
with
34 additions
and
34 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,3 +1,3 @@ | ||
{% macro trino__current_timestamp() %} | ||
{% macro trino__current_timestamp() -%} | ||
current_timestamp | ||
{% endmacro %} | ||
{%- endmacro %} |
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
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,3 +1,3 @@ | ||
{% macro trino__date_trunc(datepart, date) %} | ||
{% macro trino__date_trunc(datepart, date) -%} | ||
date_trunc('{{datepart}}', {{date}}) | ||
{% endmacro %} | ||
{%- endmacro %} |
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,3 +1,3 @@ | ||
{% macro trino__dateadd(datepart, interval, from_date_or_timestamp) %} | ||
{% macro trino__dateadd(datepart, interval, from_date_or_timestamp) -%} | ||
date_add('{{ datepart }}', {{ interval }}, {{ from_date_or_timestamp }}) | ||
{% endmacro %} | ||
{%- endmacro %} |
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,28 +1,28 @@ | ||
{% macro trino__datediff(first_date, second_date, datepart) %} | ||
{% if datepart == 'year' %} | ||
{% macro trino__datediff(first_date, second_date, datepart) -%} | ||
{%- if datepart == 'year' -%} | ||
(year(CAST({{ second_date }} AS TIMESTAMP)) - year(CAST({{ first_date }} AS TIMESTAMP))) | ||
{% elif datepart == 'quarter' %} | ||
{%- elif datepart == 'quarter' -%} | ||
({{ datediff(first_date, second_date, 'year') }} * 4) + quarter(CAST({{ second_date }} AS TIMESTAMP)) - quarter(CAST({{ first_date }} AS TIMESTAMP)) | ||
{% elif datepart == 'month' %} | ||
{%- elif datepart == 'month' -%} | ||
({{ datediff(first_date, second_date, 'year') }} * 12) + month(CAST({{ second_date }} AS TIMESTAMP)) - month(CAST({{ first_date }} AS TIMESTAMP)) | ||
{% elif datepart == 'day' %} | ||
{%- elif datepart == 'day' -%} | ||
((to_milliseconds((CAST(CAST({{ second_date }} AS TIMESTAMP) AS DATE) - CAST(CAST({{ first_date }} AS TIMESTAMP) AS DATE)))) / 86400000) | ||
{% elif datepart == 'week' %} | ||
{%- elif datepart == 'week' -%} | ||
({{ datediff(first_date, second_date, 'day') }} / 7 + case | ||
when dow(CAST({{first_date}} AS TIMESTAMP)) <= dow(CAST({{second_date}} AS TIMESTAMP)) then | ||
case when {{first_date}} <= {{second_date}} then 0 else -1 end | ||
else | ||
case when {{first_date}} <= {{second_date}} then 1 else 0 end | ||
end) | ||
{% elif datepart == 'hour' %} | ||
{%- elif datepart == 'hour' -%} | ||
({{ datediff(first_date, second_date, 'day') }} * 24 + hour(CAST({{ second_date }} AS TIMESTAMP)) - hour(CAST({{ first_date }} AS TIMESTAMP))) | ||
{% elif datepart == 'minute' %} | ||
{%- elif datepart == 'minute' -%} | ||
({{ datediff(first_date, second_date, 'hour') }} * 60 + minute(CAST({{ second_date }} AS TIMESTAMP)) - minute(CAST({{ first_date }} AS TIMESTAMP))) | ||
{% elif datepart == 'second' %} | ||
{%- elif datepart == 'second' -%} | ||
({{ datediff(first_date, second_date, 'minute') }} * 60 + second(CAST({{ second_date }} AS TIMESTAMP)) - second(CAST({{ first_date }} AS TIMESTAMP))) | ||
{% elif datepart == 'millisecond' %} | ||
{%- elif datepart == 'millisecond' -%} | ||
(to_milliseconds((CAST({{ second_date }} AS TIMESTAMP) - CAST({{ first_date }} AS TIMESTAMP)))) | ||
{% else %} | ||
{%- else -%} | ||
{% if execute %}{{ exceptions.raise_compiler_error("Unsupported datepart for macro datediff in Trino: {!r}".format(datepart)) }}{% endif %} | ||
{% endif %} | ||
{% endmacro %} | ||
{%- endif -%} | ||
{%- endmacro %} |
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,3 +1,3 @@ | ||
{% macro trino__safe_cast(field, type) %} | ||
{% macro trino__safe_cast(field, type) -%} | ||
try_cast({{field}} as {{type}}) | ||
{% endmacro %} | ||
{%- endmacro %} |
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
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