docs: def _extract_cell(args, cell_body):
    """Implements the BigQuery extract magic used to extract query or table data to GCS.
  
     The supported syntax is:
       %bq extract <args>
  
    Args:
      args: the arguments following '%bigquery extract'.
    """
  
    env = google.datalab.utils.commands.notebook_environment()
    config = google.datalab.utils.commands.parse_config(cell_body, env, False) or {}
    parameters = config.get('parameters')
    if args['table']:
      table = google.datalab.bigquery.Query.resolve_parameters(args['table'], parameters)
      source = _get_table(table)
      if not source:
        raise Exception('Could not find table %s' % table)
  
      csv_delimiter = args['delimiter'] if args['format'] == 'csv' else None
      path = google.datalab.bigquery.Query.resolve_parameters(args['path'], parameters)
      job = source.extract(path, format=args['format'], csv_delimiter=csv_delimiter,
                           csv_header=args['header'], compress=args['compress'])
    elif args['query'] or args['view']:
      source_name = args['view'] or args['query']
      source = google.datalab.utils.commands.get_notebook_item(source_name)
      if not source:
        raise Exception('Could not find ' +
                        ('view ' + args['view'] if args['view'] else 'query ' + args['query']))
      query = source if args['query'] else bigquery.Query.from_view(source)
      query_params = get_query_parameters(args, cell_body) if args['query'] else None
  
      output_options = QueryOutput.file(path=args['path'], format=args['format'],
                                        csv_delimiter=args['delimiter'],
                                        csv_header=args['header'], compress=args['compress'],
                                        use_cache=not args['nocache'])
      context = google.datalab.utils._utils._construct_context_for_args(args)
      job = query.execute(output_options, context=context, query_params=query_params)
    else:
      raise Exception('A query, table, or view is needed to extract')
  
    if job.failed:
      raise Exception('Extract failed: %s' % str(job.fatal_error))
    elif job.errors:
      raise Exception('Extract completed with errors: %s' % str(job.errors))
    return job.result()