2017-06-05 89 views
0

我有以下Python代碼:Azure存儲表返回空實體

def GetData(tableService, tableName, dataFilter): 
    keyMarkers = {} 
    keyMarkers['nextpartitionkey'] = 0 
    keyMarkers['nextrowkey'] = 0 
    b=[] 
    while True: 
     #get a batch of data 
     a = tableService.query_entities(table_name=tableName, filter=dataFilter,num_results=1000 ,marker=keyMarkers) 
     #copy results to list 
     for item in a.items: 
      b.append(item.amount.value) 
     #check to see if more data is available 
     if len(a.next_marker) == 0: 
      del a 
      break 
     #if more data available setup current position 
     keyMarkers['nextpartitionkey'] = a.next_marker['nextpartitionkey'] 
     keyMarkers['nextrowkey'] = a.next_marker['nextrowkey'] 
     #house keep temp storage 
     del a 
    #return final list 
    return b 

這是工作,但是,對於第一個結果,a.items自帶空。經過10次查詢後,它終於開始返回一些數據。這就像表格沒有我查詢的值的行。我知道它已經發生了,最終會出現。但只有在返回太多空的結果之後。

我有一個PHP代碼用於相同的目的,但它沒有得到空實體。所以我不認爲這是Azure的常見行爲。也許它的Python for Python的工作方式?

+0

即使沒有記錄返回,你是否在'a.next_marker ['nextpartitionkey']'和'a.next_marker ['nextrowkey']'中獲得了一些值? –

+0

是的,我喜歡。總是返回'next_marker'。 – rlcabral

回答

1

在第一次請求時,你可以嘗試傳遞'None'作爲標記,而不是0和0代表nextpk/nextrk的字典嗎?我不確定,但這可能會使服務混淆到使用此pk搜索表實體。

+0

這絕對是對的!我只是變成了「無」,它不僅解決了問題,而且還更快地返回了結果。 – rlcabral