diff --git a/.changes/unreleased/Fixes-20240709-145439.yaml b/.changes/unreleased/Fixes-20240709-145439.yaml new file mode 100644 index 00000000..275c6bb8 --- /dev/null +++ b/.changes/unreleased/Fixes-20240709-145439.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: add new test to test case sensitivity for column quoting in incremental models that use append_new_columns +time: 2024-07-09T14:54:39.526077-05:00 +custom: + Author: McKnight-42 + Issue: "250" diff --git a/dbt-tests-adapter/dbt/tests/adapter/incremental/fixtures.py b/dbt-tests-adapter/dbt/tests/adapter/incremental/fixtures.py index 6e130266..5116504d 100644 --- a/dbt-tests-adapter/dbt/tests/adapter/incremental/fixtures.py +++ b/dbt-tests-adapter/dbt/tests/adapter/incremental/fixtures.py @@ -303,3 +303,32 @@ from source_data """ + +_MODELS__SRC_JOBS = """ +{{ + config( + materialized='table', + ) +}} + +{% if var("version", 0) == 0 %} + + select {{ dbt.current_timestamp() }} as inserted_at, 'john' as name + +{% else %} + + select {{ dbt.current_timestamp() }} as inserted_at, 'engineer' as {{ adapter.quote('Job') }} + +{% endif %} +""" + +_MODELS__DIM_JOBS = """ +{{ + config( + materialized='incremental', + on_schema_change='append_new_columns', + ) +}} + +select * from {{ ref("src_jobs") }} +""" diff --git a/dbt-tests-adapter/dbt/tests/adapter/incremental/test_incremental_on_schema_change.py b/dbt-tests-adapter/dbt/tests/adapter/incremental/test_incremental_on_schema_change.py index 43b13ae9..8e10896b 100644 --- a/dbt-tests-adapter/dbt/tests/adapter/incremental/test_incremental_on_schema_change.py +++ b/dbt-tests-adapter/dbt/tests/adapter/incremental/test_incremental_on_schema_change.py @@ -1,7 +1,7 @@ import pytest from dbt.tests.adapter.incremental import fixtures -from dbt.tests.util import check_relations_equal, run_dbt +from dbt.tests.util import check_relations_equal, run_dbt, run_dbt_and_capture class BaseIncrementalOnSchemaChangeSetup: @@ -84,3 +84,21 @@ def test_run_incremental_fail_on_schema_change(self, project): class TestIncrementalOnSchemaChange(BaseIncrementalOnSchemaChange): pass + + +class BaseIncrementalCaseSenstivityOnSchemaChange: + @pytest.fixture(scope="class") + def models(self): + return { + "src_jobs.sql": fixtures._MODELS__SRC_JOBS, + "dim_jobs.sql": fixtures._MODELS__DIM_JOBS, + } + + def test_run_incremental_check_quoting_on_new_columns(self, project): + run_dbt(["run", "--models", "src_jobs dim_jobs", "--full-refresh"]) + + res, logs = run_dbt_and_capture(["run", "--select", "dim_jobs"]) + + run_dbt(["run", "--vars", "{'version': 1}"]) + + res, logs = run_dbt_and_capture(["run", "--select", "dim_jobs"]) diff --git a/dbt/include/global_project/macros/adapters/columns.sql b/dbt/include/global_project/macros/adapters/columns.sql index 96e6f3f2..782b9e94 100644 --- a/dbt/include/global_project/macros/adapters/columns.sql +++ b/dbt/include/global_project/macros/adapters/columns.sql @@ -123,11 +123,11 @@ alter {{ relation.type }} {{ relation.render() }} {% for column in add_columns %} - add column {{ column.name }} {{ column.data_type }}{{ ',' if not loop.last }} + add column {{ adapter.quote(column.name) }} {{ column.data_type }}{{ ',' if not loop.last }} {% endfor %}{{ ',' if add_columns and remove_columns }} {% for column in remove_columns %} - drop column {{ column.name }}{{ ',' if not loop.last }} + drop column {{ adapter.quote(column.name) }} {{ ',' if not loop.last }} {% endfor %} {%- endset -%}