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

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… 😃

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

The fix is in this PR: #952