-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support dbt v1.2 #6
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
f514198
support dbt v1.1
shiyuhang0 3099471
fix error
shiyuhang0 c40944c
Lift + shift for cross-db macros
shiyuhang0 fcf99ba
retry connection logical
shiyuhang0 ac9a784
fix github action fail
shiyuhang0 2b15a2e
test alter name
shiyuhang0 7d168fd
support grant
shiyuhang0 2c6fc2e
test python 3.10
shiyuhang0 b321e24
fix error test in test_tidb.py
shiyuhang0 7160510
fmt will be done in another pr
shiyuhang0 50b2aa1
add code annotation
shiyuhang0 945ffdc
doc
shiyuhang0 d071f22
fix doc
shiyuhang0 f3a38ea
Update dbt/include/tidb/macros/apply_grants.sql
zhangyangyu 8e83b30
fix github action
shiyuhang0 3d1c446
Merge remote-tracking branch 'origin/dbt_1.2' into dbt_1.2
shiyuhang0 0cdb5d7
fix typo
shiyuhang0 c404104
fix port
shiyuhang0 1fbc02a
Apply suggestions from code review
zhangyangyu 5e3df9b
fix port typo
shiyuhang0 dc412cb
Merge remote-tracking branch 'origin/dbt_1.2' into dbt_1.2
shiyuhang0 f2e83c0
test grant
shiyuhang0 84de1ef
fix tidb5_1
shiyuhang0 cbf0f65
fix typo
shiyuhang0 b0f175e
fix tidb4.x
shiyuhang0 64b0b21
add test for tidb 5.3
shiyuhang0 d64b591
fix typo
shiyuhang0 eca9828
Merge branch 'main' into dbt_1.2
shiyuhang0 ff4d04d
fmt
shiyuhang0 7caaae2
fix version
shiyuhang0 c1dad1b
link fix
shiyuhang0 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shiyuhang0 what if a relation object never printed the database? would save you from having to override core's version of this macro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe we can delete this override because I found that the database has been set to None in get_relation.
And I will test if it still works after delete the macro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#21