-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
0880779
to
34d2798
Compare
34d2798
to
6b58fd9
Compare
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
There was a problem hiding this 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.
@@ -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 }}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") }} |
There was a problem hiding this comment.
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).
0349d33
to
4d606e5
Compare
There was a problem hiding this 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.
4d606e5
to
51b8e64
Compare
There was a problem hiding this 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.
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 %} |
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
CHANGELOG.md
and added information about my change to the "dbt next" section.