簡體   English   中英

使用通配符選項從 BigQuery 導出到 GCS 時,有沒有辦法從大表中獲取生成的文件列表?

[英]Is there a way to get a list of the files that were generated, from a large table, when exporting from BigQuery to GCS using a wildcard option?

我使用通配符 * export 將大型 BigQuery 表導出到 GCS 中的單獨文件中。 我使用了 GCP 文檔中提供的代碼示例:

from google.cloud import bigquery
client = bigquery.Client()
bucket_name = 'bucket'
project = "project"
dataset_id = "dataset"
table_id = "table"


destination_uri = "gs://{}/{}".format(bucket_name, "table*.parquet")
dataset_ref = bigquery.DatasetReference(project, dataset_id)
table_ref = dataset_ref.table(table_id)

extract_job = client.extract_table(
    table_ref,
    destination_uri,
    # Location must match that of the source table.
    location="US",
)  # API request
extract_job.result()  # Waits for job to complete.

print(
    "Exported {}:{}.{} to {}".format(project, dataset_id, table_id, destination_uri)
)

這在我的存儲桶中生成了 19 個不同的文件,例如mytable000000000000.parquetmytable000000000001.parquet等等(最多 0000000000019)。

最好有一種自動獲取這些文件名列表的方法,這樣我就可以將它們compose在一起或循環處理它們以執行其他操作。 有沒有一種簡單的方法來編輯上面的代碼來做到這一點?

使用通配符時您不會獲得明確的列表,但請查看extract job statistics中的destinationUriFileCounts字段。 它會告訴你有多少文件存在。 在 python 中,可在此處獲得。

如果您想要更強的驗證,您還可以利用 Cloud Storage 庫並列出具有您作為提取配置的一部分提供的相同模式的對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM