From 89ea676edcfd8bf9a045c312add715084902cef2 Mon Sep 17 00:00:00 2001 From: Pedro Sousa Date: Fri, 5 Jan 2024 15:18:04 +0000 Subject: [PATCH] Test quote_identifier --- .../model_refers_different_column_cases.sql | 8 ++++ .../model_with_different_column_cases.sql | 7 +++ .../model_refers_different_column_cases.sql | 43 +++++++++++++++++++ macros/mock_builders.sql | 6 +-- macros/utils.sql | 2 +- 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 integration-tests/models/model_refers_different_column_cases.sql create mode 100644 integration-tests/models/model_with_different_column_cases.sql create mode 100644 integration-tests/tests/unit/model_refers_different_column_cases.sql diff --git a/integration-tests/models/model_refers_different_column_cases.sql b/integration-tests/models/model_refers_different_column_cases.sql new file mode 100644 index 0000000..dbc4556 --- /dev/null +++ b/integration-tests/models/model_refers_different_column_cases.sql @@ -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') }} \ No newline at end of file diff --git a/integration-tests/models/model_with_different_column_cases.sql b/integration-tests/models/model_with_different_column_cases.sql new file mode 100644 index 0000000..b4cbb23 --- /dev/null +++ b/integration-tests/models/model_with_different_column_cases.sql @@ -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 \ No newline at end of file diff --git a/integration-tests/tests/unit/model_refers_different_column_cases.sql b/integration-tests/tests/unit/model_refers_different_column_cases.sql new file mode 100644 index 0000000..99c1929 --- /dev/null +++ b/integration-tests/tests/unit/model_refers_different_column_cases.sql @@ -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 %} \ No newline at end of file diff --git a/macros/mock_builders.sql b/macros/mock_builders.sql index 63b6232..f1f80ed 100644 --- a/macros/mock_builders.sql +++ b/macros/mock_builders.sql @@ -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}) %} diff --git a/macros/utils.sql b/macros/utils.sql index 9629273..01f8358 100644 --- a/macros/utils.sql +++ b/macros/utils.sql @@ -157,7 +157,7 @@ {% if identifier.startswith('"') %} {{ return(identifier) }} {% else %} - {{ return('"' ~ identifier | upper ~ '"') }} + {{ return('"' ~ identifier ~ '"') }} {% endif %} {% endmacro %}