Skip to content

Support GROUP BY and DCOUNT queries #4751

Description

@tvaron3

Feature Summary

Add production cross-partition GROUP BY and DCOUNT query execution to the Cosmos DB Rust driver.

Feature Description

Implement full-drain grouping with per-group aggregate state and add the missing DCOUNT query-plan model and merge path.

Validation and acceptance criteria:

  • Read groupByItems from rewritten envelopes and use structural JSON hashing/equality for group keys.
  • Maintain per-group aggregate accumulators and drain all required partitions before paging grouped output.
  • Initially reject external continuation tokens for GROUP BY explicitly.
  • Add missing DCOUNT plan model fields and merge per-partition counts.
  • Preserve SELECT VALUE and aliased output shapes for DCOUNT and grouped projections.
  • Cover group-key JSON types, multiple aggregate expressions, empty groups, partition splits, and output shapes.
  • Cover DCOUNT VALUE/alias forms, empty inputs, duplicate distribution across partitions, and split behavior.

Use Case

Applications need globally correct grouped aggregates and distinct counts across all physical partitions with Cosmos-compatible projection shapes.

Alternatives

Grouping or counting only public partition pages cannot reconstruct rewritten grouping keys, aggregate state, distinct semantics, or output shapes reliably.

Additional Context

Implement under sdk/cosmos/azure_data_cosmos_driver/src/driver/dataflow/. This depends on the parent issue's groupByItems and aggregate envelopes, buffering limits, response transformation, continuation policy, and reusable tests; it also depends on the aggregate stage and the DISTINCT structural hash implementation. Cross-SDK references: .NET GroupByQueryPipelineStage, GroupingTable, DCountQueryPipelineStage, and GroupByQueryTests; Java GroupByDocumentQueryExecutionContext, GroupingTable, DCountDocumentQueryExecutionContext, and DCountInfo.

Metadata

Metadata

Assignees

No one assigned

    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
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions