Skip to content

Commit

Permalink
extending and using dbt_unit_testing's quote_identifier macro
Browse files Browse the repository at this point in the history
  • Loading branch information
dhwdeca committed Aug 4, 2023
1 parent 279e6ce commit 6d76b45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion macros/mock_builders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
left join (select
{%- for column in missing_columns %}
{%- if options.quoted_columns %}
"{{ column }}"
{{ dbt_unit_testing.quote_identifier(column, true) }}
{%- else %}
{{ column }}
{%- endif %}
Expand Down
12 changes: 7 additions & 5 deletions macros/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,31 @@
{{ return (dbt_unit_testing.merge_jsons([unit_tests_config] + configs)) }}
{% endmacro %}

{% macro quote_identifier(identifier) %}
{{ return(adapter.dispatch('quote_identifier','dbt_unit_testing')(identifier)) }}
{% macro quote_identifier(identifier, preserve_case=false) %}
{{ return(adapter.dispatch('quote_identifier','dbt_unit_testing')(identifier, preserve_case)) }}
{% endmacro %}

{% macro default__quote_identifier(identifier) -%}
{% macro default__quote_identifier(identifier, preserve_case) -%}
{% if identifier.startswith('"') %}
{{ return(identifier) }}
{% else %}
{{ return('"' ~ identifier ~ '"') }}
{% endif %}
{%- endmacro %}

{% macro bigquery__quote_identifier(identifier) %}
{% macro bigquery__quote_identifier(identifier, preserve_case) %}
{% if identifier.startswith('`') %}
{{ return(identifier) }}
{% else %}
{{ return('`' ~ identifier ~ '`') }}
{% endif %}
{% endmacro %}

{% macro snowflake__quote_identifier(identifier) %}
{% macro snowflake__quote_identifier(identifier, preserve_case) %}
{% if identifier.startswith('"') %}
{{ return(identifier) }}
{% elif preserve_case %}
{{ return('"' ~ identifier ~ '"') }}
{% else %}
{{ return('"' ~ identifier | upper ~ '"') }}
{% endif %}
Expand Down

0 comments on commit 6d76b45

Please sign in to comment.