Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

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

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**
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...