【发布时间】:2021-07-29 16:19:49
【问题描述】:
我是 GCP 的新手,我可以将 1 个文件从我的 VM 获取到 GCS,然后将其传输到 bigquery。 如何将多个文件从 GCS 传输到 Bigquery。我知道通配符 URi 是它的解决方案,但下面的代码还需要进行哪些其他更改?
def hello_gcs(event, context):
from google.cloud import bigquery
# Construct a BigQuery client object.
client = bigquery.Client()
# TODO(developer): Set table_id to the ID of the table to create.
table_id = "test_project.test_dataset.test_Table"
job_config = bigquery.LoadJobConfig(
autodetect=True,
skip_leading_rows=1,
# The source format defaults to CSV, so the line below is optional.
source_format=bigquery.SourceFormat.CSV,
)
uri = "gs://test_bucket/*.csv"
load_job = client.load_table_from_uri(
uri, table_id, job_config=job_config
) # Make an API request.
load_job.result() # Waits for the job to complete.
destination_table = client.get_table(table_id) # Make an API request.
print(f"Processing file: {file['name']}.")
由于可能有多个上传,所以我无法定义特定的表名或文件名?是否可以自动执行此任务?
每当 GCS 存储桶中有新文件时,PubSub 都会触发此功能。 谢谢
【问题讨论】:
标签: python-3.x google-bigquery google-cloud-functions google-cloud-storage google-cloud-pubsub