Skip to content

Commit

Permalink
Test quote_identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
psousa50 committed Jan 5, 2024
1 parent c8b3594 commit 89ea676
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
select
"UPPER_CASE_COLUMN",
"Mixed Case Column",
"lowercasecolumn",
UPPER_CASE_COLUMN,
MixedCaseColumn,
lower_case_column
from {{ dbt_unit_testing.ref('model_with_different_column_cases') }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
1 as "UPPER_CASE_COLUMN",
2 as "Mixed Case Column",
3 as "lowercasecolumn",
4 as UPPER_CASE_COLUMN,
5 as MixedCaseColumn,
6 as lower_case_column
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{
config(
tags=['unit-test', 'bigquery', 'snowflake', 'postgres']
)
}}

{% call dbt_unit_testing.test('model_refers_different_column_cases') %}
{% call dbt_unit_testing.mock_ref ('model_with_different_column_cases') %}
select
1 as "UPPER_CASE_COLUMN",
2 as "Mixed Case Column",
3 as "lowercasecolumn",
4 as UPPER_CASE_COLUMN,
5 as MixedCaseColumn,
6 as lower_case_column
{% endcall %}
{% call dbt_unit_testing.expect() %}
select
1 as "UPPER_CASE_COLUMN",
2 as "Mixed Case Column",
3 as "lowercasecolumn",
4 as UPPER_CASE_COLUMN,
5 as MixedCaseColumn,
6 as lower_case_column
{% endcall %}
{% endcall %}

UNION ALL

{% call dbt_unit_testing.test('model_refers_different_column_cases') %}
{% call dbt_unit_testing.mock_ref ('model_with_different_column_cases', options={"include_missing_columns": true}) %}
select 0 as c
{% endcall %}
{% call dbt_unit_testing.expect() %}
select
CAST(null AS Int) as "UPPER_CASE_COLUMN",
CAST(null AS Int) as "Mixed Case Column",
CAST(null AS Int) as "lowercasecolumn",
CAST(null AS Int) as UPPER_CASE_COLUMN,
CAST(null AS Int) as MixedCaseColumn,
CAST(null AS Int) as lower_case_column
{% endcall %}
{% endcall %}
6 changes: 3 additions & 3 deletions macros/mock_builders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
{%- if missing_columns -%}
{% set input_values_sql %}
{% set node_sql = dbt_unit_testing.build_node_sql(model_node, options.use_database_models) %}
select * from ({{ input_values_sql }}) as m1
left join (select {{ dbt_unit_testing.quote_and_join_columns(missing_columns)}}
from ({{ node_sql }}) as m2) as m3 on false
select * from ({{ input_values_sql }}) as m1
left join (select {{ dbt_unit_testing.quote_and_join_columns(missing_columns)}}
from ({{ node_sql }}) as m2) as m3 on false
{%- endset -%}
{%- endif -%}
{% do mock.update({"input_values": input_values_sql}) %}
Expand Down
2 changes: 1 addition & 1 deletion macros/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
{% if identifier.startswith('"') %}
{{ return(identifier) }}
{% else %}
{{ return('"' ~ identifier | upper ~ '"') }}
{{ return('"' ~ identifier ~ '"') }}
{% endif %}
{% endmacro %}

Expand Down

0 comments on commit 89ea676

Please sign in to comment.