Skip to content

Commit

Permalink
When column config says quote, use quotes in SQL to add comments
Browse files Browse the repository at this point in the history
Add separate test for column comments. Fix Snowflake catalog comments.
  • Loading branch information
gshank committed Sep 4, 2020
1 parent ae542dc commit 4d606e5
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
## dbt 0.19.0 (Release TBD)

### Under the hood
- If column config says quote, use quoting in SQL for adding a comment. ([#2539](https:/fishtown-analytics/dbt/issues/2539), [#2733](https:/fishtown-analytics/dbt/pull/2733))

## dbt 0.18.0 (September 03, 2020)

### Under the hood
- Added 3 more adapter methods that the new dbt-adapter-test suite can use for testing. ([#2492](https:/fishtown-analytics/dbt/issues/2492), [#2721](https:/fishtown-analytics/dbt/pull/2721))
- It is now an error to attempt installing `dbt` with a Python version less than 3.6. (resolves [#2347](https:/fishtown-analytics/dbt/issues/2347))
- Check for Postgres relation names longer than 63 and throw exception. ([#2197](https:/fishtown-analytics/dbt/issues/2197))
- Check for Postgres relation names longer than 63 and throw exception. ([#2197](https:/fishtown-analytics/dbt/issues/2197), [#2727](https:/fishtown-analytics/dbt/pull/2727))


### Fixes
Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ColumnInfo(
description: str = ''
meta: Dict[str, Any] = field(default_factory=dict)
data_type: Optional[str] = None
quote: Optional[bool] = None
tags: List[str] = field(default_factory=list)
_extra: Dict[str, Any] = field(default_factory=dict)

Expand Down
6 changes: 6 additions & 0 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ def add(
):
tags: List[str] = []
tags.extend(getattr(column, 'tags', ()))
quote: Optional[bool]
if isinstance(column, UnparsedColumn):
quote = column.quote
else:
quote = None
self.column_info[column.name] = ColumnInfo(
name=column.name,
description=description,
data_type=data_type,
meta=meta,
tags=tags,
quote=quote,
_extra=column.extra
)

Expand Down
2 changes: 1 addition & 1 deletion plugins/postgres/dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@
{% for column_name in column_dict %}
{% set comment = column_dict[column_name]['description'] %}
{% set escaped_comment = postgres_escape_comment(comment) %}
comment on column {{ relation }}.{{ column_name }} is {{ escaped_comment }};
comment on column {{ relation }}.{{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} is {{ escaped_comment }};
{% endfor %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
{% macro snowflake__alter_column_comment(relation, column_dict) -%}
alter {{ relation.type }} {{ relation }} alter
{% for column_name in column_dict %}
{{ column_name }} COMMENT $${{ column_dict[column_name]['description'] | replace('$', '[$]') }}$$ {{ ',' if not loop.last else ';' }}
{{ 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 ';' }}
{% endfor %}
{% endmacro %}

Expand Down
4 changes: 2 additions & 2 deletions plugins/snowflake/dbt/include/snowflake/macros/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
table_schema as "table_schema",
table_name as "table_name",
table_type as "table_type",
comment as "table_comment",

-- note: this is the _role_ that owns the table
table_owner as "table_owner",
Expand Down Expand Up @@ -36,12 +37,11 @@
table_catalog as "table_database",
table_schema as "table_schema",
table_name as "table_name",
null as "table_comment",

column_name as "column_name",
ordinal_position as "column_index",
data_type as "column_type",
null as "column_comment"
comment as "column_comment"

from {{ information_schema }}.columns
)
Expand Down
Loading

0 comments on commit 4d606e5

Please sign in to comment.