簡體   English   中英

大查詢 api 使用 python Api

[英]Bigquery api using python Api

我正在嘗試通過讀取存儲桶原始文件(基於存儲桶文件名,它應該創建相同的表)來自動創建 BQ 中的表,這將使用 yml 作為配置。 任何人都可以提供有關如何使用代碼示例編寫的線索。

我正在做類似的事情。 它還取決於您想如何讀取存儲桶“原始文件”,在我的例子中是 GCS 通知 + PubSub。

非常簡單的例子:

uri = "gs://" + event['attributes']['bucketId'] + "/" + filename
table = os.path.splitext(filename)[0]

#Format the filename to only numbers and letters (no special characters)
table = re.sub('[^A-Za-z0-9]+', '', table)

# Construct a BigQuery client object.
client = bigquery.Client()

# Name of the table which will be created automatically by BigQuery
table_id = project_id + "." + dataset_id + "." + table

job_config = bigquery.LoadJobConfig(
    autodetect=True,
    source_format=bigquery.SourceFormat.CSV,
)

load_job = client.load_table_from_uri(
        uri, table_id, job_config=job_config
)

如果表不存在,BigQuery 作業將自動創建表。

暫無
暫無

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

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