-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Handle more than 100 fields to compute hashid #970
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
33 changes: 33 additions & 0 deletions
33
...tegrations/bases/base-normalization/dbt-project-template/macros/cross_db_utils/concat.sql
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,33 @@ | ||
{# | ||
Overriding the following macro from dbt-utils: | ||
https://github.com/fishtown-analytics/dbt-utils/blob/0.6.2/macros/cross_db_utils/concat.sql | ||
To implement our own version of concat | ||
Because on postgres, we cannot pass more than 100 arguments to a function | ||
#} | ||
|
||
{% macro concat(fields) -%} | ||
{{ adapter.dispatch('concat')(fields) }} | ||
{%- endmacro %} | ||
|
||
{% macro default__concat(fields) -%} | ||
concat({{ fields|join(', ') }}) | ||
{%- endmacro %} | ||
|
||
{% macro alternative_concat(fields) %} | ||
{{ fields|join(' || ') }} | ||
{% endmacro %} | ||
|
||
|
||
{% macro postgres__concat(fields) %} | ||
{{ dbt_utils.alternative_concat(fields) }} | ||
{% endmacro %} | ||
|
||
|
||
{% macro redshift__concat(fields) %} | ||
{{ dbt_utils.alternative_concat(fields) }} | ||
{% endmacro %} | ||
|
||
|
||
{% macro snowflake__concat(fields) %} | ||
{{ dbt_utils.alternative_concat(fields) }} | ||
{% endmacro %} |
51 changes: 51 additions & 0 deletions
51
...ons/bases/base-normalization/dbt-project-template/macros/cross_db_utils/surrogate_key.sql
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,51 @@ | ||
{# | ||
Overriding the following macro from dbt-utils: | ||
https://github.com/fishtown-analytics/dbt-utils/blob/0.6.2/macros/sql/surrogate_key.sql | ||
To implement our own version of concat | ||
Because on postgres, we cannot pass more than 100 arguments to a function | ||
#} | ||
|
||
{%- macro surrogate_key(field_list) -%} | ||
|
||
{%- if varargs|length >= 1 or field_list is string %} | ||
|
||
{%- set error_message = ' | ||
Warning: the `surrogate_key` macro now takes a single list argument instead of \ | ||
multiple string arguments. Support for multiple string arguments will be \ | ||
deprecated in a future release of dbt-utils. The {}.{} model triggered this warning. \ | ||
'.format(model.package_name, model.name) -%} | ||
|
||
{%- do exceptions.warn(error_message) -%} | ||
|
||
{# first argument is not included in varargs, so add first element to field_list_xf #} | ||
{%- set field_list_xf = [field_list] -%} | ||
|
||
{%- for field in varargs %} | ||
{%- set _ = field_list_xf.append(field) -%} | ||
{%- endfor -%} | ||
|
||
{%- else -%} | ||
|
||
{# if using list, just set field_list_xf as field_list #} | ||
{%- set field_list_xf = field_list -%} | ||
|
||
{%- endif -%} | ||
|
||
|
||
{%- set fields = [] -%} | ||
|
||
{%- for field in field_list_xf -%} | ||
|
||
{%- set _ = fields.append( | ||
"coalesce(cast(" ~ field ~ " as " ~ dbt_utils.type_string() ~ "), '')" | ||
) -%} | ||
|
||
{%- if not loop.last %} | ||
{%- set _ = fields.append("'-'") -%} | ||
{%- endif -%} | ||
|
||
{%- endfor -%} | ||
|
||
{{dbt_utils.hash(concat(fields))}} | ||
|
||
{%- 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
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.
Can you add the link to the dbt PR?
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.
The dbt-utils PR is here: dbt-labs/dbt-utils#296