如果是larger than 1GB,BigQuery 会将导出的数据拆分为多个文件。但是您可以将这些文件与gsutil tool 合并,查看this official documentation 以了解如何使用 gsutil 执行对象组合。
由于 BigQuery 导出具有相同前缀的文件,您可以使用通配符 * 将它们合并为一个复合对象:
gsutil compose gs://example-bucket/component-obj-* gs://example-bucket/composite-object
请注意,可以在单个操作中组合的组件数量存在限制(当前为 32 个)。
此选项的缺点是每个.csv 文件的标题行将添加到复合对象中。但是您可以通过修改jobConfig 将print_header parameter 设置为False 来避免这种情况。
这是一个 Python 示例代码,但你可以使用any other BigQuery Client library:
from google.cloud import bigquery
client = bigquery.Client()
bucket_name = 'yourBucket'
project = 'bigquery-public-data'
dataset_id = 'libraries_io'
table_id = 'dependencies'
destination_uri = 'gs://{}/{}'.format(bucket_name, 'file-*.csv')
dataset_ref = client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
job_config = bigquery.job.ExtractJobConfig(print_header=False)
extract_job = client.extract_table(
table_ref,
destination_uri,
# Location must match that of the source table.
location='US',
job_config=job_config) # API request
extract_job.result() # Waits for job to complete.
print('Exported {}:{}.{} to {}'.format(
project, dataset_id, table_id, destination_uri))
最后,记得用标题行组成一个空的.csv。