'creates a new, empty table in the dataset;
If the table already exists, update the existing table.
Since BigQuery does not natively allow table upserts, this is not an
atomic operation.
:param dataset_id: the dataset to upsert the table into.
:type dataset_id: str
:param table_resource: a table resource. see
https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
:type table_resource: dict
:param project_id: the project to upsert the table into.  If None,
project will be self.project_id.
:return:'

def run_table_upsert(self, dataset_id, table_resource, project_id=None):

    table_id = table_resource['tableReference']['tableId']
    project_id = (project_id if (project_id is not None) else self.project_id)
    tables_list_resp = self.service.tables().list(projectId=project_id, datasetId=dataset_id).execute()
    while True:
        for table in tables_list_resp.get('tables', []):
            if (table['tableReference']['tableId'] == table_id):
                logging.info('table    %s:%s.%s    exists,    updating.', project_id, dataset_id, table_id)
                return self.service.tables().update(projectId=project_id, datasetId=dataset_id, tableId=table_id, body=table_resource).execute()
        if ('nextPageToken' in tables_list_resp):
            tables_list_resp = self.service.tables().list(projectId=project_id, datasetId=dataset_id, pageToken=tables_list_resp['nextPageToken']).execute()
        else:
            logging.info('table    %s:%s.%s    does    not    exist.    creating.', project_id, dataset_id, table_id)
            return self.service.tables().insert(projectId=project_id, datasetId=dataset_id, body=table_resource).execute()
