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

Feature (Redshift): option to set query group for adhoc/scheduled queries #4114

Merged
merged 3 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,36 @@ def configuration_schema(cls):
"type": "string",
"title": "SSL Mode",
"default": "prefer"
}
},
"adhoc_query_group": {
"type": "string",
"title": "Query Group for Adhoc Queries",
"default": "default"
},
"scheduled_query_group": {
"type": "string",
"title": "Query Group for Scheduled Queries",
"default": "default"
},
},
"order": ['host', 'port', 'user', 'password'],
"order": ['host', 'port', 'user', 'password', 'dbname', 'sslmode', 'adhoc_query_group', 'scheduled_query_group'],
"required": ["dbname", "user", "password", "host", "port"],
"secret": ["password"]
}

def annotate_query(self, query, metadata):
annotated = super(Redshift, self).annotate_query(query, metadata)

if metadata.get('Scheduled', False):
query_group = self.configuration.get('scheduled_query_group')
else:
query_group = self.configuration.get('adhoc_query_group')

if query_group:
set_query_group = 'set query_group to {};'.format(query_group)
annotated = '{}\n{}'.format(set_query_group, annotated)

return annotated

def _get_tables(self, schema):
# Use svv_columns to include internal & external (Spectrum) tables and views data for Redshift
Expand Down
2 changes: 2 additions & 0 deletions redash/tasks/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ def _annotate_query(self, query_runner):
self.metadata['Task ID'] = self.task.request.id
self.metadata['Query Hash'] = self.query_hash
self.metadata['Queue'] = self.task.request.delivery_info['routing_key']
self.metadata['Scheduled'] = self.scheduled_query is not None

return query_runner.annotate_query(self.query, self.metadata)

def _log_progress(self, state):
Expand Down