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

Adding autocommit property for Redshift queries for Vacuums, etc. #2242

Merged
merged 5 commits into from
Sep 27, 2017

Conversation

jamesmcm
Copy link
Contributor

@jamesmcm jamesmcm commented Sep 27, 2017

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)

@@ -359,6 +360,8 @@ class PostgresQuery(rdbms.Query):

def run(self):
connection = self.output().connect()
if self.autocommit:
Copy link
Collaborator

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?

Copy link
Collaborator

@dlstadther dlstadther left a 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?

@jamesmcm
Copy link
Contributor Author

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.

@@ -178,6 +182,10 @@ def table(self):
def query(self):
return None

@abc.abstractproperty
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@dlstadther dlstadther left a 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

@jamesmcm
Copy link
Contributor Author

Thanks, it looks good now :)

@dlstadther dlstadther merged commit 14517c1 into spotify:master Sep 27, 2017
@dlstadther
Copy link
Collaborator

Thanks @jamesmcm for contributing!

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

Successfully merging this pull request may close these issues.

2 participants