-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-2819] default__alter_relation_add_remove_columns macro does not use quoting with case sensitive Snowflake relation #256
base: main
Are you sure you want to change the base?
Changes from 14 commits
68bfa34
d6ad15c
3c922d4
8d8bad6
b221b09
2765bf0
de1893a
7fdf639
ade5d98
0cb0583
52cb472
f70650b
098fcf5
50fb497
5bc06b6
29bd5ae
7868857
1d83c86
13f3f35
253686a
ed01f64
35710fe
ecacae7
27d3cab
002bba5
8670ca2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -303,3 +303,34 @@ | |||||
|
||||||
from source_data | ||||||
""" | ||||||
|
||||||
_MODELS__SRC_ARTISTS = """ | ||||||
{{ | ||||||
config( | ||||||
materialized='table', | ||||||
) | ||||||
}} | ||||||
|
||||||
{% if var("version", 0) == 0 %} | ||||||
|
||||||
select {{ dbt.current_timestamp() }} as inserted_at, 'john' as name | ||||||
|
||||||
{% else %} | ||||||
|
||||||
-- add a non-zero version to the end of the command to get a different version: | ||||||
-- --vars "{'version': 1}" | ||||||
select {{ dbt.current_timestamp() }} as inserted_at, 'john' as Name, 'engineer' as "Job" | ||||||
mikealfare marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if using
Suggested change
|
||||||
|
||||||
{% endif %} | ||||||
""" | ||||||
|
||||||
_MODELS__DIM_ARTISTS = """ | ||||||
{{ | ||||||
config( | ||||||
materialized='incremental', | ||||||
on_schema_change='append_new_columns', | ||||||
) | ||||||
}} | ||||||
|
||||||
select * from {{ ref("src_artists") }} | ||||||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,27 @@ 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_artists.sql": fixtures._MODELS__SRC_ARTISTS, | ||
"dim_artists.sql": fixtures._MODELS__DIM_ARTISTS, | ||
} | ||
|
||
def test_run_incremental_check_quoting_on_new_columns(self, project): | ||
select = "src_artists dim_artists" | ||
run_dbt(["run", "--models", select, "--full-refresh"]) | ||
run_dbt(["show", "--inline", "select * from {{ ref('dim_artists') }}"]) | ||
res, logs = run_dbt_and_capture( | ||
["show", "--inline", "select * from {{ ref('dim_artists') }}"] | ||
) | ||
assert "Job" not in logs | ||
run_dbt(["run", "--vars", "{'version': 1}"]) | ||
run_dbt(["show", "--inline", "select * from {{ ref('dim_artists') }}"]) | ||
res, logs = run_dbt_and_capture( | ||
["show", "--inline", "select * from {{ ref('dim_artists') }}"] | ||
) | ||
assert "Job" in logs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Instead of the assertions here, you might be able to just rely upon From the original bug report in #250, my understanding was that it actually produced an error. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we always want to quote? Or is there a config that we need to condition on, similar to the quote policy for relation names? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adapter.quote leverages the same quote policy as relation names There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mikealfare are you thinking something like this (for relations) or this (for columns)? In this particular case, I think we need to match the quoting from here (which would mean always quoting via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: here are the primary resources I've been using when researching quoting or case-sensitive issues: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dbeatty10 oh these are really cool. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @colin-rogers-dbt @dbeatty10 If the objective is to always quote the column in this case, that's fine. I just know we've run into issues before where we quote something that doesn't get quoted, or vice versa, and then it fails a condition in a filter where it's supposed to pass. I haven't seen it with columns, so maybe it doesn't apply here. |
||
{% 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 -%} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The content of the model looks like "jobs" now instead of "artists". So ideally they'd match instead of being different.