gpt4 book ai didi

azure - Azure存储表查询实体真的有数量限制吗?

转载 作者:行者123 更新时间:2023-12-03 00:36:53 25 4
gpt4 key购买 nike

来自MSDN ,查询服务返回的实体数量似乎有限制:

A query against the Table service may return a maximum of 1,000 entities at one time and may execute for a maximum of five seconds.

但是当我编写一个示例来展示这个问题时,我没有发现返回实体数量有任何限制,这是我的关键代码:

public class DataProvider
{
public static string PartitionKey
{
get { return "PartitionKey"; }
}

public static IEnumerable<CustomerEntity> MoreThanThousandData()
{
var result = new List<CustomerEntity>();
for (int i = 0; i < 1200; i++)
{
result.Add(new CustomerEntity(PartitionKey, Guid.NewGuid().ToString())
{
Name = Guid.NewGuid().ToString(),
Age = new Random().Next(10, 70)
});
}

return result;
}
}

向表中插入 1200 个实体:

public class AfterOptimize
{
public void InsertDataToTable()
{
var cloudData = DataProvider.MoreThanThousandData();
Console.WriteLine("Plan to insert {0} entities to the table.", cloudData.Count());

InsertDataToTableInternal(AzureTableService.Table, cloudData);
}

private void InsertDataToTableInternal(CloudTable table, IEnumerable<ITableEntity> data)
{
var splitedData = data.Chunk(100);
Parallel.ForEach(splitedData, item =>
{
var batchInsertOperation = new TableBatchOperation();
foreach (var tableEntity in item)
{
batchInsertOperation.Add(TableOperation.Insert(tableEntity));
}

table.ExecuteBatch(batchInsertOperation);
});
}
}

然后,从表中读取,这里的分区键都是一样的:

public void ReadCloudData()
{
InsertMoreThanOneThousandDataToTable();
var query =
new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey",
QueryComparisons.Equal, DataProvider.PartitionKey));
var result = AzureTableService.Table.ExecuteQuery(query);
Console.WriteLine("Read {0} entities from table.", result.Count()); // output 1200
}

我只使用了最新的 Azure 存储 .NET 客户端 API。

最佳答案

我无法找到文档链接,但 ExecuteQuery 方法在内部处理延续 token 并将返回表中的所有实体。因此,您所看到的行为是正确的。

如果您在执行此代码时运行 Fiddler,您会注意到多个请求被发送到表服务。第一个请求将没有继续 token ,但在后续请求中,您将看到 NextPartitionKeyNextRowKey 查询字符串参数。

关于azure - Azure存储表查询实体真的有数量限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com