Skip to content

Commit

Permalink
Fix including missing columns on columns with reserved names
Browse files Browse the repository at this point in the history
  • Loading branch information
psousa50 committed Sep 25, 2023
1 parent 7b492ce commit 94a246a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion integration-tests/tests/unit/reserved_column_names_mocking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
}}

{% call dbt_unit_testing.test('model_references_model_with_reserved_column_name', 'sample test') %}
{% call dbt_unit_testing.mock_ref ('model_with_reserved_column_name') %}
{% call dbt_unit_testing.mock_ref ('model_with_reserved_column_name', options={"include_missing_columns": true}) %}
select 1 as a, 'b' as b, 1 as "END"
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 1 as a, 'b' as b, 1 as "END"
{% endcall %}
{% endcall %}

UNION ALL

{% call dbt_unit_testing.test('model_references_model_with_reserved_column_name', 'sample test') %}
{% call dbt_unit_testing.mock_ref ('model_with_reserved_column_name', options={"include_missing_columns": true}) %}
select 1 as a, 'b' as b
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 1 as a, 'b' as b
{% endcall %}
{% endcall %}

2 changes: 1 addition & 1 deletion macros/mock_builders.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
{% 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 {{ missing_columns | join (",")}}
left join (select {{ dbt_unit_testing.quote_and_join_columns(missing_columns)}}
from ({{ node_sql }}) as m2) as m3 on false
{%- endset -%}
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion macros/utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endmacro %}

{% macro extract_columns_difference(cl1, cl2) %}
{% set columns = cl1 | map('lower') | list | reject('in', cl2 | map('lower') | list) | list %}
{% set columns = cl1 | reject('in', cl2) | list %}
{{ return(columns) }}
{% endmacro %}

Expand Down

0 comments on commit 94a246a

Please sign in to comment.