2016-02-26 55 views
1

您好我在datalab上使用ipython筆記本時遇到問題。Datalab不會填充bigQuery表格

我想寫一個表的結果到一個bigQuery表中,但它不工作,任何人都說使用insert_data(dataframe)函數,但它不填充我的表。 爲了簡化問題,我嘗試讀取表並將其寫入剛創建的表(具有相同的模式),但不起作用。誰能告訴我我錯在哪裏?

import gcp 
import gcp.bigquery as bq 

#read the data 
df = bq.Query('SELECT 1 as a, 2 as b FROM [publicdata:samples.wikipedia] LIMIT 3').to_dataframe() 

#creation of a dataset and extraction of the schema 
dataset = bq.DataSet('prova1') 
dataset.create(friendly_name='aaa', description='bbb') 
schema = bq.Schema.from_dataframe(df) 

#creation of the table 
temptable = bq.Table('prova1.prova2').create(schema=schema, overwrite=True) 

#I try to put the same data into the temptable just created 
temptable.insert_data(df) 

回答

1

調用insert_data會做一個HTTP POST,並返回一旦做到這一點。但是,數據顯示在BQ表中可能需要一段時間(最長可達幾分鐘)。嘗試在使用表格之前等一會兒。我們也許可以在以後的更新來解決這個問題,see this

的哈克的方式來阻止,直到準備,現在應該是這樣的:

import time 
while True: 
    info = temptable._api.tables_get(temptable._name_parts) 
    if 'streamingBuffer' not in info: 
    break 
    if info['streamingBuffer']['estimatedRows'] > 0: 
    break 
    time.sleep(5)