2 回答

TA貢獻1789條經(jīng)驗 獲得超10個贊
在 BigQuery導(dǎo)出限制中,提到 CSV 不支持嵌套和重復(fù)數(shù)據(jù)。因此,嘗試導(dǎo)出到 Avro 或 JSON:
from google.cloud import bigquery
client = bigquery.Client()
bucket_name = 'your_bucket'
project = 'bigquery-public-data'
dataset_id = 'samples'
table_id = 'shakespeare'
destination_uri = 'gs://{}/{}'.format(bucket_name, '<your_file>')
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
configuration = bigquery.job.ExtractJobConfig()
#For AVRO
#configuration.destination_format ='AVRO'
#For JSON
#configuration.destination_format ='NEWLINE_DELIMITED_JSON'
extract_job = client.extract_table(
table_ref,
destination_uri,
job_config=configuration,
location='US')
extract_job.result()
希望能幫助到你。

TA貢獻1942條經(jīng)驗 獲得超3個贊
現(xiàn)在無法測試,但也許這有效:
from google.cloud import bigquery as bq
ejc = bq.ExtractJobConfig()
ejc.destination_format='NEWLINE_DELIMITED_JSON'
extract_job = client.extract_table(
table_ref,
destination_uri,
# Location must match that of the source table.
location='US',
job_config=ejc) # API request
這個想法是使用 JSON 而不是 CSV,以便您支持嵌套數(shù)據(jù)。
添加回答
舉報