-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature:支持多个新 SQL 语法,统一了 string 类型为小写,时间类型时区设定为 UTC,并优化了 dbt seed 读取 …
…CSV 的效率。
- Loading branch information
1 parent
a52c5f1
commit 89db11e
Showing
35 changed files
with
948 additions
and
14 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 +1 @@ | ||
version = "1.8.0-alpha7" | ||
version = "1.8.0-dev" |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{# https://help.aliyun.com/zh/maxcompute/user-guide/any-value #} | ||
{% macro maxcompute__any_value(expression) -%} | ||
|
||
any_value({{ expression }}) | ||
|
||
{%- 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro maxcompute__array_append(array, new_element) -%} | ||
concat({{ array }}, array({{ new_element }})) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- 7 is the length of 'array()', I don't know how to judge if array is empty other than this method | ||
{% macro maxcompute__array_concat(array_1, array_2) -%} | ||
concat({{ array_1 }}, {{ array_2 }}) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% macro maxcompute__array_construct(inputs, data_type) -%} | ||
{%- if inputs|length > 0 -%} | ||
{%- if data_type == 'string' -%} | ||
array({{ '\"' + inputs|join('\", \"') + '\"' }}) | ||
{%- else -%} | ||
array({{ inputs|join(', ')}}) | ||
{%- endif -%} | ||
{%- else -%} | ||
{%- if data_type == 'string' -%} | ||
array() | ||
{%- elif data_type == 'integer' or data_type == 'int'-%} | ||
array_remove(array(1), 1) | ||
{%- elif data_type == 'bigint' -%} | ||
array_remove(array(1L), 1L) | ||
{%- elif data_type == 'decimal' -%} | ||
array_remove(array(1BD), 1BD) | ||
{%- elif data_type == 'timestamp' -%} | ||
array_remove(array(TIMESTAMP '2017-11-11 00:00:00'), TIMESTAMP '2017-11-11 00:00:00') | ||
{%- else -%} | ||
{{ exceptions.raise_compiler_error("Unsupport datatype when create empty array ~ '" ~ data_type ~ "'") }} | ||
{%- endif -%} | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
-- The boolean function is an aggregate function. | ||
-- When there is true in the bool type group, it returns true, otherwise it returns false. | ||
|
||
{% macro maxcompute__bool_or(expression) -%} | ||
max({{ expression }}) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- https://help.aliyun.com/zh/maxcompute/user-guide/cast | ||
{% macro maxcompute__cast(field, type) %} | ||
cast({{field}} as {{type}}) | ||
{% 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- https://docs.getdbt.com/reference/dbt-jinja-functions/cross-database-macros#cast_bool_to_text | ||
-- need to consider 'NULL' | ||
{% macro maxcompute__cast_bool_to_text(field) -%} | ||
tolower(cast({{ field }} as string)) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro maxcompute__concat(fields) -%} | ||
concat({{ fields|join(', ') }}) | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% macro maxcompute__date(year, month, day) -%} | ||
{%- set dt = modules.datetime.date(year, month, day) -%} | ||
{%- set iso_8601_formatted_date = dt.strftime('%Y-%m-%d') -%} | ||
to_date('{{ iso_8601_formatted_date }}') | ||
{%- 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% macro get_intervals_between(start_date, end_date, datepart) -%} | ||
{{ return(adapter.dispatch('get_intervals_between', 'dbt')(start_date, end_date, datepart)) }} | ||
{%- endmacro %} | ||
|
||
{% macro default__get_intervals_between(start_date, end_date, datepart) -%} | ||
{%- call statement('get_intervals_between', fetch_result=True) %} | ||
|
||
select {{ dbt.datediff(start_date, end_date, datepart) }} | ||
|
||
{%- endcall -%} | ||
|
||
{%- set value_list = load_result('get_intervals_between') -%} | ||
|
||
{%- if value_list and value_list['data'] -%} | ||
{%- set values = value_list['data'] | map(attribute=0) | list %} | ||
{{ return(values[0]) }} | ||
{%- else -%} | ||
{{ return(1) }} | ||
{%- endif -%} | ||
|
||
{%- endmacro %} | ||
|
||
|
||
|
||
|
||
{% macro date_spine(datepart, start_date, end_date) %} | ||
{{ return(adapter.dispatch('date_spine', 'dbt')(datepart, start_date, end_date)) }} | ||
{%- endmacro %} | ||
|
||
{% macro default__date_spine(datepart, start_date, end_date) %} | ||
|
||
|
||
{# call as follows: | ||
|
||
date_spine( | ||
"day", | ||
"to_date('01/01/2016', 'mm/dd/yyyy')", | ||
"dbt.dateadd(week, 1, current_date)" | ||
) #} | ||
|
||
|
||
with rawdata as ( | ||
|
||
{{dbt.generate_series( | ||
dbt.get_intervals_between(start_date, end_date, datepart) | ||
)}} | ||
|
||
), | ||
|
||
all_periods as ( | ||
|
||
select ( | ||
{{ | ||
dbt.dateadd( | ||
datepart, | ||
"row_number() over (order by 1) - 1", | ||
start_date | ||
) | ||
}} | ||
) as date_{{datepart}} | ||
from rawdata | ||
|
||
), | ||
|
||
filtered as ( | ||
|
||
select * | ||
from all_periods | ||
where date_{{datepart}} <= {{ end_date }} | ||
|
||
) | ||
|
||
select * from filtered | ||
|
||
{% 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- https://help.aliyun.com/zh/maxcompute/user-guide/datetrunc | ||
{% macro maxcompute__date_trunc(datepart, date) -%} | ||
{%- if datepart in ['day', 'month', 'year', 'hour'] %} | ||
datetrunc({{date}}, '{{datepart}}') | ||
{%- elif datepart in ['minute', 'second'] -%} | ||
{%- set diviser -%} | ||
{%- if datepart == 'minute' -%} 60 | ||
{%- else -%} 1 | ||
{%- endif -%} | ||
{%- endset -%} | ||
from_unixtime(unix_timestamp({{date}}) - (unix_timestamp({{date}}) % {{diviser}})) | ||
{%- else -%} | ||
{{ exceptions.raise_compiler_error("macro datetrunc not support for datepart ~ '" ~ datepart ~ "'") }} | ||
{%- 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,9 +1,16 @@ | ||
{% macro maxcompute__dateadd(datepart, interval, from_date_or_timestamp) %} | ||
{%- if datepart in ['day', 'month', 'year'] %} | ||
{%- if datepart in ['day', 'month', 'year', 'hour'] %} | ||
dateadd({{ from_date_or_timestamp }}, {{ interval }}, '{{ datepart }}') | ||
{%- elif datepart == 'hour' -%} | ||
from_unixtime(unix_timestamp({{from_date_or_timestamp}}) + {{interval}}*3600) | ||
{%- elif datepart == 'quarter' -%} | ||
dateadd({{ from_date_or_timestamp }}, {{ interval }}*3, 'month') | ||
{%- elif datepart in ['minute', 'second'] -%} | ||
{%- set multiplier -%} | ||
{%- if datepart == 'minute' -%} 60 | ||
{%- else -%} 1 | ||
{%- endif -%} | ||
{%- endset -%} | ||
from_unixtime(unix_timestamp({{from_date_or_timestamp}}) + {{interval}}*{{multiplier}}) | ||
{%- else -%} | ||
{{ exceptions.raise_compiler_error("macro dateadd not implemented for datepart ~ '" ~ datepart ~ "' ~ on ODPS") }} | ||
{{ exceptions.raise_compiler_error("macro dateadd not support for datepart ~ '" ~ datepart ~ "'") }} | ||
{%- endif -%} | ||
{% endmacro %} |
Oops, something went wrong.