-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Adding autocommit property for Redshift queries for Vacuums, etc. #2242
Conversation
… can run VACUUMs in Redshift
Necessary to run VACUUM in Redshift.
luigi/contrib/postgres.py
Outdated
@@ -359,6 +360,8 @@ class PostgresQuery(rdbms.Query): | |||
|
|||
def run(self): | |||
connection = self.output().connect() | |||
if self.autocommit: |
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.
You'll want to initialize this in rdbms.Query
. Set its default to False
?
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.
In addition to my one comment, could you try to add a test?
Okay, please check the new commit. I couldn't find an easy way of getting the autocommit status from the postgres server, so for now the test just uses the attribute on the connection. |
luigi/contrib/rdbms.py
Outdated
@@ -178,6 +182,10 @@ def table(self): | |||
def query(self): | |||
return None | |||
|
|||
@abc.abstractproperty |
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 don't think this needs to be an abstractproperty
. You shouldn't require the user to override it. Just a plain @property
should suffice.
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.
Oops, I fixed this now. Thanks.
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.
Looks like you've got some flake8 errors. Please fix then LGTM
Thanks, it looks good now :) |
Thanks @jamesmcm for contributing! |
This solves #2047
I've added the ability to override the autocommit property in Postgres Queries (used by Redshift Queries) - this will allow the user to make queries in autocommit mode as some operations require this.
The user only needs to set:
autocommit = True
in their RedshiftQuery subclass to make use of it.
Specifically this was done so that we could run VACUUMs in Redshift from Luigi.
I've tested it locally against our database, but I couldn't get the tox tests to run on my machine.
(Sorry for the 2 separate commits, it seems my attempt at squashing them failed)