def wait_for_table_load(load_job: bigquery.job.LoadJob, table_ref: bigquery.table.TableReference) -> bool: """Wait for a table LoadJob to finish, and log its status. Args: load_job: BigQuery LoadJob whose result to wait for. table_ref: TableReference to retrieve final table status. Returns: True if no errors were raised, else False. """ try: # Wait for table load job to complete. load_job.result(_BQ_LOAD_WAIT_TIMEOUT_SECONDS) logging.info("Load job %s for table %s.%s.%s completed successfully.", load_job.job_id, table_ref.project, table_ref.dataset_id, table_ref.table_id) destination_table = bq_utils.client().get_table(table_ref) logging.info("Loaded %d rows in table %s.%s.%s", destination_table.num_rows, destination_table.project, destination_table.dataset_id, destination_table.table_id) return True except (exceptions.NotFound, exceptions.BadRequest, concurrent.futures.TimeoutError): # type: ignore logging.exception("Failed to load table %s.%s.%s", table_ref.project, table_ref.dataset_id, table_ref.table_id) return False
def wait_for_table_load(big_query_client: BigQueryClient, load_job: bigquery.job.LoadJob) -> bool: """Wait for a table LoadJob to finish, and log its status. Args: big_query_client: A BigQueryClient for querying the result table load_job: BigQuery LoadJob whose result to wait for. Returns: True if no errors were raised, else False. """ try: # Wait for table load job to complete. load_job.result(_BQ_LOAD_WAIT_TIMEOUT_SECONDS) logging.info("Load job %s for table %s.%s.%s completed successfully.", load_job.job_id, load_job.destination.project, load_job.destination.dataset_id, load_job.destination.table_id) destination_table = big_query_client.get_table( big_query_client.dataset_ref_for_id( load_job.destination.dataset_id), load_job.destination.table_id) logging.info("Loaded %d rows in table %s.%s.%s", destination_table.num_rows, load_job.destination.project, load_job.destination.dataset_id, load_job.destination.table_id) return True except (exceptions.NotFound, exceptions.BadRequest, concurrent.futures.TimeoutError): # type: ignore logging.exception("Failed to load table %s.%s.%s", load_job.destination.project, load_job.destination.dataset_id, load_job.destination.table_id) return False
def _report_job_exception(job: bigquery.job.LoadJob) -> None: with error_handler(f"Exception thrown from BigQuery job {job.job_id}"): result = job.result() logger.info( f"BigQuery job {job.job_id} completed with result: {result}")