在Azure表存储上查询是否有效,超出了一定数量的实体?[英] Querying on Azure table storage doesnt work beyond a certain number of entities?

本文是小编为大家收集整理的关于在Azure表存储上查询是否有效,超出了一定数量的实体?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

考虑我的场景.我有大约200个分区,每个分区都有大约1000个Rowkeys(实体)甚至更多.因此,当我进行任何查询的查询获取记录时,该记录是持久的截止日期(以" Z"开头)时,它不会返回任何结果.

以下是示例查询 -

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

当我从初始字母开始的通道传递时,它会正确返回实体,但是当我以概率" z"开头时,它不会返回任何实体.

知道我如何解决这个问题?

编辑:

查询字符串

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

查询的提琴手响应

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

推荐答案

这是一个示例代码,它根据要通过的查询来获取所需的尽可能多的实体;在我的环境中,这将返回10,000多个实体,并自动处理延续令牌.我不确定它正在使用的SDK版本,但它应该与1.7一起使用.这里的魔术是由Astableservicequery执行的,这是SDK提供的扩展方法,同时执行分页和自动重试.

_tableName变量包含我表的名称.

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>();

上面的代码取决于称为mydata1的类,以这样的定义:

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

希望这会有所帮助...

本文地址:https://www.itbaoku.cn/post/1557140.html

问题描述

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

推荐答案

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