Querying on Azure table storage doesnt work beyond a certain number of entities?

穿精又带淫゛_ 提交于 2020-01-25 19:57:24

问题


Consider my scenario. I have about 200 partitions and each partition has about 1000 rowkeys(entities) or even more. So when i am making any query fetching records of a partition which is albhabetically last(starting with "z"), it doesnt return any results.

Below is a sample query -

audioRecordServiceContext.QueryableEntities
                         .Where(p => p.PartitionKey == channel && 
                                     p.IsDedication == true && 
                                     p.IsBroadcast == true && 
                                     p.BroadcastTime >= time && 
                                     p.BroadcastTime < time.AddHours(1))
                         .ToList();

When i pass a channel starting with initial alphabets it returns entities properly but when I give a channel starting with probabaly "Z", it doesnt return any entities.

Any idea how i can tackle this issue?

EDIT:

Query string

http://sampleservice/devstoreaccount1/AudioRecord()?$filter=Username eq 'username'

Fiddler response for the query

**HTTP/1.1 200 OK
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/atom+xml;charset=utf-8
Server: Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 06dff157-f693-49a6-ade7-b7165a4d3dfb
x-ms-version: 2009-09-19
x-ms-continuation-NextPartitionKey: 1!16!QWZnaGFuaXN0YW4-
x-ms-continuation-NextRowKey: 1!48!YTZiOGQxZmYtYjNkYy00NDEyLTk2YmItZTViNmUyMWNhYzJi
Date: Wed, 04 Sep 2013 12:19:03 GMT**

回答1:


Here is a sample code that fetches as many entities as needed based on the query being passed; in my environment this returns over 10,000 entities and it handles the continuation tokens automatically. I am not 100% sure of the SDK version this is using, but it should work with 1.7. The magic here is performed by the AsTableServiceQuery, which is an extension method provided by the SDK that performs both the pagination, and automatic retries.

The _tableName variable contains the name of my table.

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
            TableServiceContext serviceContext = tableClient.GetDataServiceContext();

            var partitionQuery =
                (from e in serviceContext.CreateQuery<MyData1>(_tableName)
                 where e.PartitionKey.CompareTo("15") >= 0 && e.PartitionKey.CompareTo("39") <= 0
                 select new MyData1()
                 {
                     PartitionKey = e.PartitionKey,
                     RowKey = e.RowKey,
                     Timestamp = e.Timestamp,
                     Message = e.Message,
                     Level = e.Level,
                     Severity = e.Severity
                 }
                 ).AsTableServiceQuery();

            return partitionQuery.ToList<MyData1>();

The above code depends on a class called MyData1, defined as such:

public class MyData1 : TableServiceEntity
{
    public string Message { get; set; }
    public string Level { get; set; }
    public string Severity { get; set; }
}

Hope this helps...



来源:https://stackoverflow.com/questions/18467181/querying-on-azure-table-storage-doesnt-work-beyond-a-certain-number-of-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!