question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using OrderBy on field with possible NULL value: System.NotSupportedException: Cannot execute cross partition order-by queries on mix types

See original GitHub issue

Describe the bug I’m performing this code:

var otherItems = _container.GetItemLinqQueryable<CosmosItem>(true)
    .Where(i => i.Type != "Unboxed")
    .OrderBy(i => i.OptionalField3_Sortable);

which results in the CosmosDB SQL query: SELECT VALUE root FROM root WHERE (root["Type"] != "Unboxed") ORDER BY root["OptionalField3_Sortable"] ASC

Unfortunately, this query fails with:

Unhandled Exception: System.NotSupportedException: Cannot execute cross partition order-by queries on mix types. Consider using IS_STRING/IS_NUMBER to get around this exception. Expect type: Null. Actual type: String. Item value: Microsoft.Azure.Cosmos.Query.OrderByItem. at Microsoft.Azure.Cosmos.Query.ParallelQuery.OrderByConsumeComparer.CheckTypeMatching(IList`1 items1, IList`1 items2) at Microsoft.Azure.Cosmos.Query.ParallelQuery.OrderByConsumeComparer.CompareOrderByItems(IList`1 items1, IList`1 items2) at Microsoft.Azure.Cosmos.Query.CosmosOrderByItemQueryExecutionContext.OrderByEqualityComparer.Equals(CosmosElement x, CosmosElement y) at Microsoft.Azure.Cosmos.Query.ItemProducer.<MoveNextAsync>d__64.MoveNext()

Additional context My container contains items which have OptionalFIeld3_Sortable be either String values, or null. The container’s partition key is set on Type

PS: I’m very new at using CosmosDB, so it’s very possible I’m doing something wrong here… 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
bchong95commented, Oct 31, 2019

The fix is in this PR: #952

0reactions
bchong95commented, Jan 5, 2021

@wahyuen You can track this PR which adds the fix for continuation token support on ORDER BY undefined:

https://github.com/Azure/azure-cosmos-dotnet-v3/pull/2103

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to order by data in Azure Cosmos db
Following is the error message we got: Expecting string but got No value. cannot execute cross partition order by queries on mixed types....
Read more >
{"Errors":["Cross partition query only supports 'VALUE ...
I'm passing below cosmos db query in source and when trying to preview the data getting the error. What are the possible ways...
Read more >
Cross-partition ORDER BY queries available in Azure ...
The Azure Cosmos DB Java SDK and Azure Cosmos DB Node.js SDK are available. Both include support for TOP and ORDER BY queries...
Read more >
Language Integrated Query (LINQ) and Lambda Expressions
Solution. Use the EnumerableMessageQueue class to write a LINQ query to retrieve messages using the System.Messaging.MessageQueue type: string queuePath ...
Read more >
Issue sorting with null values
Hello,. Using soql query i am able to sort the records. The records are being sorted based on a field in asc or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found