【发布时间】:2023-04-10 22:02:01
【问题描述】:
我正在努力将大型数据集从 bigquery 导出到 Goolge 云存储并转换为压缩格式。在 Google 云存储中,我有文件大小限制(每个文件的最大文件大小为 1GB)。因此,我在导出时使用拆分和同情技术来拆分数据。示例代码如下:
gcs_destination_uri = 'gs://{}/{}'.format(bucket_name, 'wikipedia-*.csv.gz')
gcs_bucket = storage_client.get_bucket(bucket_name)
# Job Config
job_config = bigquery.job.ExtractJobConfig()
job_config.compression = bigquery.Compression.GZIP
def bigquery_datalake_load():
dataset_ref = bigquery_client.dataset(dataset_id, project=project)
table_ref = dataset_ref.table(table_id)
table = bigquery_client.get_table(table_ref) # API Request
row_count = table.num_rows
extract_job = bigquery_client.extract_table(
table_ref,
gcs_destination_uri,
location='US',
job_config=job_config) # API request
logging.info('BigQuery extract Started.... Wait for the job to complete.')
extract_job.result() # Waits for job to complete.
print('Exported {}:{}.{} to {}'.format(
project, dataset_id, table_id, gcs_destination_uri))
# [END bigquery_extract_table]
此代码将大型数据集拆分并压缩为 .gz 格式,但它返回多个压缩文件,大小在 40MB 到 70MB 之间四舍五入。
我正在尝试生成大小为 1GB(每个文件)的压缩文件。有什么办法可以做到吗?
【问题讨论】:
标签: python-3.x google-cloud-platform google-bigquery google-cloud-storage