-
Notifications
You must be signed in to change notification settings - Fork 155
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
DISTKEY and SORTKEY should be in quotations #74
Conversation
7b1a724
to
16aa366
Compare
@solackerman can you create a model + reflection tests with a column name with spaces in? class SortKeyDistKeyWithSpaces(Base):
__tablename__ = 'sort_key_with_spaces'
col1 = sa.Column('col with spaces', sa.Integer(), primary_key=True)
__table_args__ = {
'redshift_diststyle': 'EVEN',
'redshift_sortkey': 'col with spaces',
'redshift_distkey': 'col with spaces',
} |
done. |
@jklukas any thoughts? |
@@ -255,7 +255,8 @@ def post_create_table(self, table): | |||
for key in keys] | |||
if interleaved_sortkey: | |||
text += " INTERLEAVED" | |||
text += " SORTKEY ({0})".format(", ".join(keys)) | |||
text += " SORTKEY ({0})".format( | |||
", ".join('"' + key + '"' for key in keys)) |
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.
I think we can have our cake and eat it too. SQLAlchemy's IdentifierPreparer.quote
method exists to conditionally quote identifiers. I think we should use that here rather than putting in explicit quotes. It would be safer (there might be some edge cases we aren't considering if column names contain quotes themselves) and it means quotes aren't added to identifiers unless necessary, which would make output more natural.
So I think we could use something like:
sortkey_string = ", ".join(self.preparer.quote(key) for key in keys)
text += " SORTKEY ({0})".format(sortkey_string)
Thanks for finding this bug and putting together the PR, @solackerman. Would you agree that conditional quoting is the way to go? |
Totally agree, that's much more elegant. I'll update the PR shortly. |
done. |
This looks great! +1 |
@@ -44,7 +44,7 @@ class ReflectionSortKey(Base): | |||
col2 = sa.Column(sa.Integer()) | |||
__table_args__ = ( | |||
{'redshift_diststyle': 'EVEN', | |||
'redshift_sortkey': ('col1, col2')} | |||
'redshift_sortkey': ('col1', 'col2')} |
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.
Is there any chance of this being a breaking change?
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.
Might be worth documenting the fact you can no longer include two columns in one string in the sortkey
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.
I'd agree that this is a breaking change that should be included in the CHANGES.rst
@graingert - Do you want to give a final +1 before we merge? I just remembered that we should probably have a note in the changelog about this as well. We should probably have a CONTRIBUTING.md to write a checklist for PRs. |
👍 |
@solackerman can you update the CHANGELOG because this is a breaking change. |
Done. |
+1 |
@solackerman can you squash these together into one, please. |
done. |
will there be a new release coming soon? |
@solackerman 0.5.0 is out now |
Amazing! Thanks :) |
Redshift column names can contain spaces. A column name like
Foo Bar
will become a sql statement looking like thiswhich will fail. This PR quotify's DISTKEY and SORTKEY, so they will appear like this: