'Execute a query (or retrieve recent results).
:qparam string query: The query text to execute
:qparam number query_id: The query object to update with the result (optional)
:qparam number max_age: If query results less than `max_age` seconds old are available, return them, otherwise execute the query; if omitted, always execute
:qparam number data_source_id: ID of data source to query'

@require_permission('execute_query')
def post(self):

    params = request.get_json(force=True)
    parameter_values = collect_parameters_from_request(request.args)
    query = params['query']
    max_age = int(params.get('max_age', (-1)))
    query_id = params.get('query_id', 'adhoc')
    data_source = models.DataSource.get_by_id_and_org(params.get('data_source_id'), self.current_org)
    if (not has_access(data_source.groups, self.current_user, not_view_only)):
        return ({'job': {'status': 4, 'error': 'You    do    not    have    permission    to    run    queries    with    this    data    source.'}}, 403)
    self.record_event({'action': 'execute_query', 'timestamp': int(time.time()), 'object_id': data_source.id, 'object_type': 'data_source', 'query': query})
    return run_query(data_source, parameter_values, query, query_id, max_age)
