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

When column config says quote, use quotes in SQL to add comments #2733

Merged
merged 1 commit into from
Sep 8, 2020

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Sep 1, 2020

resolves #2539

Description

When 'persist_docs' was turned on, an error occurred if a column had config 'quote: true' because the DDL to add the comment did not quote the column name. This fix passes the column quote config on to the ColumnInfo object and checks that config when constructing the SQL to add a comment.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt next" section.

@cla-bot cla-bot bot added the cla:yes label Sep 1, 2020
@gshank gshank marked this pull request as draft September 1, 2020 17:28
@gshank gshank requested review from beckjake and jtcohen6 and removed request for beckjake and jtcohen6 September 1, 2020 18:01
@beckjake
Copy link
Contributor

beckjake commented Sep 1, 2020

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Sep 1, 2020

The cla-bot has been summoned, and re-checked this pull request!

@gshank gshank marked this pull request as ready for review September 1, 2020 20:00
Copy link
Contributor

@beckjake beckjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly right to me, though I don't see any changes to support snowflake, nor any tests for it. I have some inline comments as well.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -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'] == True else column_name }} is {{ escaped_comment }};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
comment on column {{ relation }}.{{ adapter.quote(column_name) if column_dict[column_name]['quote'] == True else 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 }};

True is the only truthy value we need to care about for quote, so no need to actually compare it to True.

@@ -0,0 +1 @@
select 1 as {{ adapter.quote("test2id") }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't think this is a very useful test for postgres/redshift. I know columns that start with numbers aren't allowed in bigquery, but this column doesn't require quoting on postgres/redshift and would work fine regardless, so that's not much of a test. Snowflake will have case-sensitivity issues so it's probably still useful there.

I think you'll have to turn this into its own test case. I have done a bit of reading and I actually think that it's fine to exclude Bigquery from this test entirely: since the only things allowed in column names don't require quoting, and unquoted column names are case-preserving, quoting columns on Bigquery seems to be totally meaningless (identifiers are less restrictive, so quoting matters there: hyphens come to mind).

@jtcohen6 jtcohen6 changed the base branch from dev/marian-anderson to dev/0.18.1 September 4, 2020 19:28
Copy link
Contributor

@beckjake beckjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the release version/changelog nonsense is all sorted, this looks good to me! Love to see those snowflake tests behaving like everyone else too (comments in the catalog), so thanks for getting that in there!

Add separate test for column comments. Fix Snowflake catalog comments.
Copy link
Contributor

@jtcohen6 jtcohen6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work on this!

Thinking beyond this PR: I wonder if there's a good way to abstract over

{{ adapter.quote(column_name) if column_dict[column_name]['quote'] else column_name }}

Since that's effectively what we'd need to fix #2468 as well.

@gshank gshank merged commit fb40efe into dev/0.18.1 Sep 8, 2020
@beckjake
Copy link
Contributor

beckjake commented Sep 8, 2020

it does seem like a macro or adapter method that we could write, doesn't it?

{% macro quoted_column(column_dict, column_name) %}
  {% set result = column_name %}
  {% if column_dict[column_name]['quote'] %}
    {% set result = adapter.quote(column_name) %}
  {% endif %}
  {% do return(result) %}
{% endmacro %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

persist_docs should consider column quoting
3 participants