From 43025ca009a2e419b425487bb9d294d2e1690a62 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Wed, 26 May 2021 11:47:25 -0300 Subject: [PATCH 1/4] feat: spark adapter to change column comment --- dbt/include/spark/macros/adapters.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dbt/include/spark/macros/adapters.sql b/dbt/include/spark/macros/adapters.sql index a45b0d1ae..8ea69eea9 100644 --- a/dbt/include/spark/macros/adapters.sql +++ b/dbt/include/spark/macros/adapters.sql @@ -162,3 +162,16 @@ {% macro spark__generate_database_name(custom_database_name=none, node=none) -%} {% do return(None) %} {%- endmacro %} + +{% macro spark__alter_column_comment(relation, column_dict) %} + {% if config.get('file_format', validator=validation.any[basestring]) == 'delta' %} + {% for column_name in column_dict %} + {% set comment = column_dict[column_name]['description'] %} + {% set comment_query %} + ALTER TABLE {{ relation }} ALTER COLUMN {{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} COMMENT '{{ comment }}'; + {% endset %} + {% do run_query(comment_query) %} + {% endfor %} + {% endif %} +{% endmacro %} + From 64f81d22a13deed3c7ceb295d0a89216db533a81 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 27 May 2021 10:39:30 -0300 Subject: [PATCH 2/4] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d33fe69d5..9e57e6075 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ The following configurations can be supplied to models run with the dbt-spark pl | clustered_by | Each partition in the created table will be split into a fixed number of buckets by the specified columns. | Optional | `cluster_1` | | buckets | The number of buckets to create while clustering | Required if `clustered_by` is specified | `8` | | incremental_strategy | The strategy to use for incremental models (`append`, `insert_overwrite`, or `merge`). | Optional (default: `append`) | `merge` | -| persist_docs | Whether dbt should include the model description as a table `comment` | Optional | `{'relation': true}` | +| persist_docs | Whether dbt should include the model description as a table or column `comment` | Optional | `{'relation': true, 'columns': true}` | **Incremental Models** From 0062d1e5a528300e01093390a22c1b0d786fe523 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Tue, 1 Jun 2021 10:46:40 -0300 Subject: [PATCH 3/4] feat: convert statement to lowercase --- dbt/include/spark/macros/adapters.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt/include/spark/macros/adapters.sql b/dbt/include/spark/macros/adapters.sql index 8ea69eea9..1b1d613e1 100644 --- a/dbt/include/spark/macros/adapters.sql +++ b/dbt/include/spark/macros/adapters.sql @@ -168,7 +168,7 @@ {% for column_name in column_dict %} {% set comment = column_dict[column_name]['description'] %} {% set comment_query %} - ALTER TABLE {{ relation }} ALTER COLUMN {{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} COMMENT '{{ comment }}'; + alter table {{ relation }} change column {{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }} comment '{{ comment }}'; {% endset %} {% do run_query(comment_query) %} {% endfor %} From 95feb731380137798a402666a0d2225f045e593c Mon Sep 17 00:00:00 2001 From: Cristiano Date: Fri, 4 Jun 2021 15:11:46 -0300 Subject: [PATCH 4/4] feat: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 002a0a1e7..75ec62377 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## dbt next +### Features +- Add support for column comment ([#170](https://github.com/fishtown-analytics/dbt-spark/pull/170)) + ### Fixes - Cast `table_owner` to string to avoid errors generating docs ([#158](https://github.com/fishtown-analytics/dbt-spark/pull/158), [#159](https://github.com/fishtown-analytics/dbt-spark/pull/159)) @@ -13,6 +16,7 @@ - [@friendofasquid](https://github.com/friendofasquid) ([#159](https://github.com/fishtown-analytics/dbt-spark/pull/159)) - [@franloza](https://github.com/franloza) ([#160](https://github.com/fishtown-analytics/dbt-spark/pull/160)) - [@Fokko](https://github.com/Fokko) ([#165](https://github.com/fishtown-analytics/dbt-spark/pull/165)) +- [@cristianoperez](https://github.com/cristianoperez) ([#170](https://github.com/fishtown-analytics/dbt-spark/pull/170)) ## dbt-spark 0.19.1 (Release TBD)