Skip to content
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

Check if a snowflake column exists before altering its comment #3149

Merged
merged 9 commits into from
May 13, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix compiled sql for ephemeral models ([#3317](https:/fishtown-analytics/dbt/issues/3317), [#3318](https:/fishtown-analytics/dbt/pull/3318))
- Now generating `run_results.json` even when no nodes are selected ([#3313](https:/fishtown-analytics/dbt/issues/3313), [#3315](https:/fishtown-analytics/dbt/pull/3315))
- Stop clobbering default keyword arguments for jinja test definitions ([#3329](https:/fishtown-analytics/dbt/issues/3329), [#3340](https:/fishtown-analytics/dbt/pull/3340))
- Update the snowflake adapter to only comment on a column if it exists when using the persist_docs config ([#3039](https:/fishtown-analytics/dbt/issues/3039), [#3149](https:/fishtown-analytics/dbt/pull/3149))

### Under the hood
- Added logic for registry requests to raise a timeout error after a response hangs out for 30 seconds and 5 attempts have been made to reach the endpoint ([#3177](https:/fishtown-analytics/dbt/issues/3177), [#3275](https:/fishtown-analytics/dbt/pull/3275))
Expand All @@ -12,6 +13,7 @@ Contributors:
- [@TeddyCr](https:/TeddyCr) ([#3275](https:/fishtown-analytics/dbt/pull/3275))
- [@panasenco](https:/panasenco) ([#3315](https:/fishtown-analytics/dbt/pull/3315))
- [@peiwangdb](https:/peiwangdb) ([#3344](https:/fishtown-analytics/dbt/pull/3344))
- [@elikastelein](https:/elikastelein) ([#3149](https:/fishtown-analytics/dbt/pull/3149))

## dbt 0.20.0b1 (May 03, 2021)

Expand Down
3 changes: 1 addition & 2 deletions plugins/snowflake/dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@


{% macro snowflake__alter_column_comment(relation, column_dict) -%}
alter {{ relation.type }} {{ relation }} alter
{% for column_name in column_dict %}
{{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} COMMENT $${{ column_dict[column_name]['description'] | replace('$', '[$]') }}$$ {{ ',' if not loop.last else ';' }}
comment if exists on column {{ relation }}.{{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} is $${{ column_dict[column_name]['description'] | replace('$', '[$]') }}$$;
{% endfor %}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ config(materialized='table') }}
select 1 as id, 'Ed' as name
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
models:
- name: missing_column
columns:
- name: id
description: "test id column description"
- name: column_that_does_not_exist
description: "comment that cannot be created"
35 changes: 35 additions & 0 deletions test/integration/060_persist_docs_tests/test_persist_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,38 @@ def test_bigquery_persist_docs(self):

level_3_column = node['columns']['level_1.level_2.level_3_a']
assert level_3_column['comment'] == "level_3 column description"


class TestPersistDocsColumnMissing(BasePersistDocsTest):
@property
def project_config(self):
return {
'config-version': 2,
'models': {
'test': {
'+persist_docs': {
"columns": True,
},
}
}
}

@property
def models(self):
return 'models-column-missing'

@use_profile('snowflake')
def test_snowflake_missing_column(self):
self.run_dbt()
self.run_dbt(['docs', 'generate'])
with open('target/catalog.json') as fp:
catalog_data = json.load(fp)
assert 'nodes' in catalog_data

table_node = catalog_data['nodes']['model.test.missing_column']
table_id_comment = table_node['columns']['ID']['comment']
assert table_id_comment.startswith('test id column description')

@use_profile('bigquery')
def test_bigquery_missing_column(self):
self.run_dbt()