-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dbt v1.2 1. Lift + shift for cross-db macros 2. Support connection retry 3. Support grant 4. Doc Update Co-authored-by: Shi Yuhang <1136742008.com>
- Loading branch information
1 parent
89fbbda
commit ad580d7
Showing
46 changed files
with
1,657 additions
and
48 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
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,29 @@ | ||
-- support Select/Insert/Delete/Update now | ||
{% macro default__get_show_grant_sql(relation) %} | ||
|
||
select case(Table_priv) when null then null else 'select' end as privilege_type, `User` as grantee from mysql.tables_priv where `DB` = '{{relation.schema}}' and `Table_name` = '{{relation.identifier}}' and Table_priv like '%Select%' | ||
union ALL | ||
select case(Table_priv) when null then null else 'insert' end as privilege_type, `User` as grantee from mysql.tables_priv where `DB` = '{{relation.schema}}' and `Table_name` = '{{relation.identifier}}' and Table_priv like '%Insert%' | ||
union ALL | ||
select case(Table_priv) when null then null else 'update' end as privilege_type, `User` as grantee from mysql.tables_priv where `DB` = '{{relation.schema}}' and `Table_name` = '{{relation.identifier}}' and Table_priv like '%Update%' | ||
union ALL | ||
select case(Table_priv) when null then null else 'delete' end as privilege_type, `User` as grantee from mysql.tables_priv where `DB` = '{{relation.schema}}' and `Table_name` = '{{relation.identifier}}' and Table_priv like '%Delete%' | ||
|
||
{% endmacro %} | ||
|
||
{%- macro tidb__get_grant_sql(relation, privilege, grantees) -%} | ||
grant {{ privilege }} on {{ relation }} to {{ '\"' + grantees|join('\", \"') + '\"' }} | ||
{%- endmacro -%} | ||
|
||
{%- macro tidb__get_revoke_sql(relation, privilege, grantees) -%} | ||
revoke {{ privilege }} on {{ relation }} from {{ '\"' + grantees|join('\", \"') + '\"' }} | ||
{%- endmacro -%} | ||
|
||
-- tidb-dbt does not support multi=true now, so we need to split every grant/revoke statement | ||
{% macro tidb__call_dcl_statements(dcl_statement_list) %} | ||
{% for dcl_statement in dcl_statement_list %} | ||
{% call statement('grant_or_revoke') %} | ||
{{ dcl_statement }} | ||
{% endcall %} | ||
{% endfor %} | ||
{% 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
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,7 @@ | ||
-- bool_or is an agg function which will return true once any expression is true | ||
-- use max to replace it | ||
{% macro tidb__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,8 @@ | ||
{% macro tidb__cast_bool_to_text(field) %} | ||
|
||
case {{ field }} | ||
when true then 'true' | ||
when false then 'false' | ||
end | ||
|
||
{% 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,31 @@ | ||
-- date_trunc can truncate date with given datepart(year,month,quarter,day is supported) | ||
{% macro tidb__date_trunc(datepart, date) -%} | ||
|
||
{%- if datepart =='day' -%} | ||
|
||
DATE_FORMAT({{date}}, '%Y-%m-%d') | ||
|
||
{%- elif datepart == 'month' -%} | ||
|
||
DATE_FORMAT({{date}}, '%Y-%m-01') | ||
|
||
{%- elif datepart == 'quarter' -%} | ||
|
||
case QUARTER({{date}}) | ||
when 1 then DATE_FORMAT({{date}}, '%Y-01-01') | ||
when 2 then DATE_FORMAT({{date}}, '%Y-04-01') | ||
when 2 then DATE_FORMAT({{date}}, '%Y-07-01') | ||
when 2 then DATE_FORMAT({{date}}, '%Y-10-01') | ||
end | ||
|
||
{%- elif datepart == 'year' -%} | ||
|
||
DATE_FORMAT({{date}}, '%Y-01-01') | ||
|
||
{%- else -%} | ||
|
||
{{ exceptions.raise_compiler_error("macro date_trunc not implemented for datepart ~ '" ~ datepart ~ "' ~ on TiDB") }} | ||
|
||
{%- 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,9 @@ | ||
-- add interval to given from_date_or_timestamp with datepart(day,month,hour...) | ||
{% macro tidb__dateadd(datepart, interval, from_date_or_timestamp) %} | ||
|
||
DATE_ADD( | ||
{{ from_date_or_timestamp }}, | ||
interval {{ interval }} {{ datepart }} | ||
) | ||
|
||
{% 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,14 @@ | ||
-- the behavior is a little different from default_datediff that it will round down rather than round up | ||
-- and millisecond is not supported | ||
{% macro tidb__datediff(first_date, second_date, datepart) -%} | ||
{%- if datepart =='millisecond' -%} | ||
|
||
{{ exceptions.raise_compiler_error("macro datediff not implemented for datepart ~ '" ~ datepart ~ "' ~ on TiDB") }} | ||
|
||
{%- else -%} | ||
|
||
TIMESTAMPDIFF({{datepart}},{{first_date}},{{second_date}}) | ||
|
||
{%- 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,5 @@ | ||
{% macro tidb__hash(field) -%} | ||
|
||
md5(cast({{ field }} as CHAR)) | ||
|
||
{%- endmacro %} |
Oops, something went wrong.