2017-08-17 19 views
0

下面的代碼:BIGQUERY:任務完成了,但job.query_results()返回total_bytes_processed無

import time 
from google.cloud import bigquery 
client = bigquery.Client() 
query = """\ 
select 3 as x 
""" 
dataset = client.dataset('dataset_name') 
table = dataset.table(name='table_name') 
job = client.run_async_query('job_name_76', query) 
job.write_disposition = 'WRITE_TRUNCATE' 
job.destination = table 
job.begin() 
retry_count = 100 
while retry_count > 0 and job.state != 'DONE': 
    retry_count -= 1 
    time.sleep(10) 
    job.reload() 
print job.state 
print job.query_results().name 
print job.query_results().total_bytes_processed 

打印:

DONE 
job_name_76 
None 

我不明白爲什麼total_bytes_processed回報None因爲工作完成和文檔說:

total_bytes_processed:

查詢處理的字節總數。

參見 https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#totalBytesProcessed

返回類型:int或NoneType

返回:服務器(無直到由服務器設置)上計數生成。

回答

2

看起來你是對的。正如您在code中看到的那樣,當前API不會處理有關處理字節的數據。

這已被報道在這個issue,正如你可以在這個tseaver's PR看到這個功能已經實現,並等待審覈/合併所以大概我們太快了有生產此代碼。

在平均時間,你可以從job_properties屬性得到的結果,如:

from google.cloud.bigquery import Client 
import types 
import os 

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path/to/key.json' 

bc = Client() 
query = 'your query' 
job = bc.run_async_query('name', query) 
job.begin() 
wait_job(job) 

query_results = job._properties['statistics'].get('query') 

query_results應該有totalBytesProcessed你正在尋找。

+0

謝謝你的回答。我也發現'job._properties ['statistics'] ['totalBytesProcessed']'給了我結果。 – gus87