簡體   English   中英

BigQuery | Python | 從BigQuery表VIEW導出數據

[英]BigQuery | Python | Export data from BigQuery table VIEW

這是一個簡單的代碼,可以CSV格式從Biq查詢導出到Google存儲空間

def export_data():

  client = bigquery.Client()

  project = 'xxxxx'
  dataset_id = 'xxx'
  table_id = 'xxx'
  bucket_name = 'xxx'

  destination_uri = 'gs://{}/{}'.format(bucket_name, 'EXPORT_FILE.csv')
  dataset_ref = client.dataset(dataset_id, project=project)
  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='EU')  # API request
  extract_job.result()  # Waits for job to complete.

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

它非常適合常規表,但是當我嘗試從已保存的表VIEW中導出數據時,由於以下錯誤而失敗:

BadRequest: 400 Using table xxx:xxx.xxx@123456 is not allowed for this operation because of its type. Try using a different table that is of type TABLE.

是否存在從表視圖導出數據的任何方法?

我想要實現的是從BigQuery以CSV格式獲取數據,並將其上傳到Google Analytics(分析)產品數據

BigQuery視圖受到一些限制

  • 您無法運行從視圖導出數據的BigQuery作業。

我沒有在答案中發布超過10多個其他限制,因為它們可能會更改。 點擊鏈接閱讀所有內容。

您需要查詢視圖並將結果寫入目標表,然后在目標表上發出導出作業。

暫無
暫無

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

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