Example #1
0
def task_6(task: tasks.Task, job: tasks.Job) -> str:
  """task06: a simple task creating a BigQuery asynchronous job."""
  del job
  logging.info('Running task_6.')
  _, project = google.auth.default()
  dst_table_id = f'{project}.{task.task_args["dest_table"]}'
  client = bigquery.Client()
  job_config = bigquery.QueryJobConfig(
      destination=dst_table_id,
      use_legacy_sql=False,
      write_disposition=bigquery.job.WriteDisposition.WRITE_TRUNCATE)

  sql = """
        SELECT * FROM bigquery-public-data.samples.shakespeare
        WHERE corpus = 'hamlet'
        ORDER BY word_count DESC
        LIMIT 10
  """

  # The `shakespeare` sample dataset is located in the US region. If you get an
  # error about the dataset not being available in your location,
  # try using a different dataset, or one of your own. For example, for EU
  # region you can use this query:
  #
  # sql = """
  #       SELECT rental_id, duration, end_station_name
  #       FROM `bigquery-public-data.london_bicycles.cycle_hire`
  #       ORDER BY start_date DESC
  #       LIMIT 10;
  # """

  query_job = client.query(sql, job_config=job_config)
  bq_job_id = query_job.job_id
  logging.info('Launched bq job %s.', bq_job_id)
  return futures.BigQueryFuture(bq_job_id)
 def task1(job, task):
     mark_unused(job, task)
     return futures.BigQueryFuture(trigger_id='test-bq-job-id')