code: def create_and_wait_for_completion(self, sql_query):
          
          header = {'content-type': 'application/json'}
          data = self.send(self.api_url,
                           http_method="POST",
                           json_body={"query": sql_query},
                           http_header=header)
  
          warnings.warn('Batch SQL job created with job_id: {job_id}'.format(job_id=data['job_id']))
  
          while data and data['status'] in BATCH_JOBS_PENDING_STATUSES:
              time.sleep(BATCH_READ_STATUS_AFTER_SECONDS)
              data = self.read(data['job_id'])
  
          if data['status'] in BATCH_JOBS_FAILED_STATUSES:
              raise CartoException(_("Batch SQL job failed with result: {data}".format(data=data)))
  
          return data
docs: Creates a new batch SQL query and waits for its completion or failure
  
          Batch SQL jobs are asynchronous, once created this method
          automatically queries the job status until it's one of 'done',
          'failed', 'canceled', 'unknown'
  
          :param sql_query: The SQL query to be used
          :type sql_query: str or list of str
  
          :return: Response data, either as json or as a regular response.content
                      object
          :rtype: object
  
          :raise: CartoException when there's an exception in the BatchSQLJob execution or the batch job status is one of the BATCH_JOBS_FAILED_STATUSES ('failed', 'canceled', 'unknown')