'Executes a BigQuery SQL query. See here:
https://cloud.google.com/bigquery/docs/reference/v2/jobs
For more details about the configuration parameter.
:param configuration: The configuration parameter maps directly to
BigQuery\'s configuration field in the job object. See
https://cloud.google.com/bigquery/docs/reference/v2/jobs for
details.'

def run_with_configuration(self, configuration):

    jobs = self.service.jobs()
    job_data = {'configuration': configuration}
    query_reply = jobs.insert(projectId=self.project_id, body=job_data).execute()
    job_id = query_reply['jobReference']['jobId']
    keep_polling_job = True
    while keep_polling_job:
        try:
            job = jobs.get(projectId=self.project_id, jobId=job_id).execute()
            if (job['status']['state'] == 'DONE'):
                keep_polling_job = False
                if ('errorResult' in job['status']):
                    raise Exception('BigQuery    job    failed.    Final    error    was:    {}.    The    job    was:    {}'.format(job['status']['errorResult'], job))
            else:
                logging.info('Waiting    for    job    to    complete    :    %s,    %s', self.project_id, job_id)
                time.sleep(5)
        except HttpError as err:
            if (err.resp.status in [500, 503]):
                logging.info('%s:    Retryable    error,    waiting    for    job    to    complete:    %s', err.resp.status, job_id)
                time.sleep(5)
            else:
                raise Exception('BigQuery    job    status    check    failed.    Final    error    was:    %s', err.resp.status)
    return job_id
