bigquery.job.ExtractJobConfig()

Posted

技术标签:

【中文标题】bigquery.job.ExtractJobConfig()【英文标题】: 【发布时间】:2018-06-14 17:40:22 【问题描述】:

我想使用 python 2.7 和 pycharm 从 Bigquery 中提取一个表。我按照谷歌云官方网站(https://cloud.google.com/bigquery/docs/exporting-data)提出的步骤,但它一直给我“AttributeError:'module'对象没有属性'ExtractJobConfig'”错误。

代码:

from gcloud import bigquery

def bigquery_get_rows ():

    #ININCIALIZACAO DO CLIENTE DE FORMA EXPLICITA
    json_key = "path/to/my/json_key_File.json"
    #storage_client = storage.Client.from_service_account_json(json_key)
    bq_client = bigquery.Client.from_service_account_json(json_key,project='my_project_name')
    print("\nPeguei o Cliente\n")

    # Make an authenticated API request
    #buckets = list(storage_client.list_buckets())
    #print(buckets)
    print("\nPRINTEI OS BUCKETS PARA TESTAR SE PEGOU O CLIENTE MERMO\n")
    #print(storage_client)
    print(bq_client)
    print("\n NAO EH QUE EU PEGUEI O TAL DO CLIENTE MERMO")

    #Setando ambiente
    project = 'my_project'
    print(project)
    bucket_name = 'my_bucket'
    print(bucket_name)
    destination_uri = 'gs:///'.format(bucket_name, 'TESTE_Lista_Padrao_Mailchimp_Automatizada.json')
    print(destination_uri)
    dataset_ref = bq_client.dataset('my_dataser_ref')
    print(dataset_ref)
    table_ref = dataset_ref.table(name='my_table_ref')
    print(table_ref)

    #Configuracao do job
    job_config = 
    job_config.destination_format = (bigquery.DestinationFormat.NEWLINE_DELIMITED_JSON)

    #Extraindo tabela
    extract_job = bq_client.extract_table(table_ref, destination_uri, job_config=job_config,location='US')  # API request
    extract_job.result()  # Waits for job to complete.
    print('Exported :. to '.format(project, dataset_id, table_id, destination_uri))

bigquery_get_rows()

【问题讨论】:

【参考方案1】:

原来我使用了错误的库。

我刚变了

from gcloud import bigquery

from google.cloud import bigquery

它现在正在工作

【讨论】:

以上是关于bigquery.job.ExtractJobConfig()的主要内容,如果未能解决你的问题,请参考以下文章