Skip to content

Support streaming ORDER BY queries #4756

Description

@tvaron3

Feature Summary

Add production, resumable cross-partition streaming ORDER BY execution to the Cosmos DB Rust driver.

Feature Description

Implement a production StreamingOrderedMerge stage over Gateway rewritten result envelopes.

Validation and acceptance criteria:

  • Consume rewritten envelopes containing ORDER BY values and return only the public payload.
  • Compare multiple ORDER BY columns with independent ascending/descending directions using Cosmos JSON comparison semantics.
  • Resolve equal sort keys deterministically using RID and partition-range tie-breakers.
  • Replenish the merge heap correctly as each partition page is consumed.
  • Honor requested output page sizing without losing buffered items.
  • Persist durable per-range and intra-page continuation state.
  • Repair continuation state after partition splits without duplication or omission.
  • Cover null, undefined, mixed JSON types, duplicate keys, empty pages, TOP composition, resume, and partition splits.

Use Case

Applications need globally ordered cross-partition results that can be paged, resumed, and repaired after physical partition changes without sacrificing deterministic Cosmos ordering.

Alternatives

Collecting and sorting all results is not suitable for large resumable queries and cannot provide the required split-safe continuation behavior.

Additional Context

Implement under sdk/cosmos/azure_data_cosmos_driver/src/driver/dataflow/. This depends on the parent issue's pipeline factory, rewritten-query application, internal envelopes, response transformation, continuation policy, and reusable dataflow tests. Cross-SDK references: .NET Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CrossPartition/OrderBy/OrderByCrossPartitionQueryPipelineStage.cs, OrderByContinuationToken.cs, and Microsoft.Azure.Cosmos.EmulatorTests/Query/OrderByQueryTests.cs; Java sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/query/OrderByDocumentQueryExecutionContext.java, OrderByContinuationToken.java, and orderbyquery/.

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.CosmosThe azure_cosmos crate

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Needs Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions