Does the Azure Storage Table query entities really has number limitations?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 05:10:55

问题


From MSDN, it seems there's a limitation for the number of entities returned by the Query service:

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.

But as I wrote a sample to show this issue, I didn't find any limitations for the number of returned entities, here is my key code:

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;
    }
}

Insert 1200 entities to the table:

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

Then, read from the table, the partition key are all the same here:

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
}

I only used the latest Azure storage .NET client API.


回答1:


I'm not able to find a documentation link but ExecuteQuery method handles continuation token internally and will return all entities in a table. Thus the behavior you're seeing is correct.

If you run Fiddler when you are executing this code, you will notice multiple requests are sent to table service. First request would be without continuation token but in subsequent requests you will see NextPartitionKey and NextRowKey querystring parameters.



来源:https://stackoverflow.com/questions/24821093/does-the-azure-storage-table-query-entities-really-has-number-limitations

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