Skip to content

Commit

Permalink
Merge pull request #2733 from fishtown-analytics/fix/2539-comment-quo…
Browse files Browse the repository at this point in the history
…ting

When column config says quote, use quotes in SQL to add comments
  • Loading branch information
gshank authored Sep 8, 2020
2 parents fa8a4f2 + 51b8e64 commit fb40efe
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## dbt 0.18.1 (Release TBD)

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

## dbt 0.18.0 (September 03, 2020)

## dbt 0.18.0rc2 (September 03, 2020)
Expand All @@ -7,7 +12,7 @@
### Under the hood
- Added 3 more adapter methods that the new dbt-adapter-test suite can use for testing. ([#2492](https://github.com/fishtown-analytics/dbt/issues/2492), [#2721](https://github.com/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://github.com/fishtown-analytics/dbt/issues/2347))
- Check for Postgres relation names longer than 63 and throw exception. ([#2197](https://github.com/fishtown-analytics/dbt/issues/2197))
- Check for Postgres relation names longer than 63 and throw exception. ([#2197](https://github.com/fishtown-analytics/dbt/issues/2197), [#2727](https://github.com/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 fb40efe

Please sign in to comment.