我的查询应该返回超过1000行。但是,query_entities一次查询仅返回1000行。 因此,我想在结果查询超过1000行时使用重新生成的令牌,以获取查询应返回的所有行。但我无法检索x-ms-continuation属性。
#coding:utf-8
class Use_Azure_Data:
def __init__(self, account_name, sas_token):
self._account_name = account_name
self._sas_token = sas_token
#Auth
def _set_table_service(self):
table_service = TableService(account_name=self._account_name, sas_token=self._sas_token)
return(table_service)
def Retrives_datas(self, days_before):
before_now = datetime.datetime.now() - datetime.timedelta(days=days_before)
now = before_now.isoformat()
filter = "Timestamp gt datetime'" + now + "'"
Query = self.Table_Service.query_entities('MyTable', filter = filter, timeout=None)
if hasattr(Query, 'x-ms-continuation'):
print("x-ms-continuation attribut for Query EXIST.")
else:
print("x-ms-continuation attribut for Query NOT EXIST.
Table_Service = property(_set_table_service)
Data = Use_Azure_Data('MyAccount', 'MySASkey' )
Data.Retrives_datas(7)
查询EXIST的x-ms-continuation属性。
我想检索x-ms-continutation以使用它来获取所有行,而我的查询将对此
答案 0 :(得分:0)
如果您使用的是azure-cosmosdb-table的最新软件包,则应使用marker
而不是x-ms-continuation
。
示例代码如下:
table_service = TableService(account_name, account_key)
i=0
marker = None
while True:
tasks = table_service.query_entities(table_name, data_filter,
marker = marker,
num_results=1000)
for task in tasks:
i += 1
print(task)
if tasks.next_marker is not None and len(tasks.next_marker) > 0:
marker = tasks.next_marker
else:
break
print i
您可以查看query_entities on GitHub的定义: