使用Cosmos DB SQL API同时运行查询
我遇到了一个问题,即Cosmos SDK生成一个查询,该查询的错误太多了
// A list with over 100k items
var carPositionIds = new List<CarPositionsIds>()
...
var iterator = CarContainer
.GetItemLinqQueryable<Car>(true)
.Where(x => carPositionIds.Contain(x.Id))
.ToFeedIterator();
:SQL查询文本超过了Azure CosmosDB中30720个字符的最大限制,
我知道这是因为.CONTAINS。 因此,我有一个大查询,而是将carpositionD列表分为较小的列表,并
var ListOfIds = carPositionIds.Split(10000); // Returns a IEnumerable<IEnumerable<T>>, where each list has up to 10000 items
var conTasks = new List<Task<FeedResponse<Car>>>();
foreach(var ids in listOfIds)
{
var iterator = CarContainer
.GetItemLinqQueryable<Car>(true)
.Where(x => ids.Contain(x.Id))
.ToFeedIterator();
while(iterator.HasMoreResults)
{
var i = iterator.ReadNextAsync();
conTasks.Add(i);
{
}
await Task.WhenAll(conTasks);
var cars = new List<Cars>();
foreach(var t in conTasks)
{
cars.AddRange(t.Result);
}
在每次运行此运行时同时运行许多较小的查询,我会在汽车列表中获得不同数量的汽车。如何同时运行多个查询?
I ran into a problem where the Cosmos SDK was generating a query, that had too many characters
// A list with over 100k items
var carPositionIds = new List<CarPositionsIds>()
...
var iterator = CarContainer
.GetItemLinqQueryable<Car>(true)
.Where(x => carPositionIds.Contain(x.Id))
.ToFeedIterator();
The error: The SQL query text exceeded the maximum limit of 30720 characters in Azure CosmosDB
I understood it was because of the .Contains.
So rather then have one big query, i split the carPositionIds list into smaller lists and run many smaller queries concurrently
var ListOfIds = carPositionIds.Split(10000); // Returns a IEnumerable<IEnumerable<T>>, where each list has up to 10000 items
var conTasks = new List<Task<FeedResponse<Car>>>();
foreach(var ids in listOfIds)
{
var iterator = CarContainer
.GetItemLinqQueryable<Car>(true)
.Where(x => ids.Contain(x.Id))
.ToFeedIterator();
while(iterator.HasMoreResults)
{
var i = iterator.ReadNextAsync();
conTasks.Add(i);
{
}
await Task.WhenAll(conTasks);
var cars = new List<Cars>();
foreach(var t in conTasks)
{
cars.AddRange(t.Result);
}
Everytime I run this, I get different amount of Cars in the Cars list. How can I run multiple queries concurrently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Thank you and glad that you have cleared the
在此处发布答案,以便对其他社区成员有帮助。
以下是分辨率步骤:
Thank you and glad that you have cleared the issue.
Posting the answer here so that it can be helpful for other community members.
Below is the resolution steps: