[Cosmos] Feed Range API#4149
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new FeedRange abstraction and accompanying ContainerClient APIs to let azure_data_cosmos consumers reason about physical partition (EPK) ranges, leveraging the driver’s EPK computation for correct MultiHash / hierarchical partition key support.
Changes:
- Introduces
FeedRangewith cross-SDK compatible serialization plus containment/overlap helpers. - Adds
ContainerClient::{read_feed_ranges, feed_range_from_partition_key}with optional routing map cache bypass. - Exposes select driver model types/APIs (EPK + PK range + PK values) needed by the SDK implementation and adds emulator + unit test coverage.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/mod.rs | Registers the new feed range emulator test module. |
| sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_feed_ranges.rs | Adds emulator integration tests for reading feed ranges and PK→range mapping (including HPK prefix cases). |
| sdk/cosmos/azure_data_cosmos/src/options/mod.rs | Adds ReadFeedRangesOptions with force_refresh support. |
| sdk/cosmos/azure_data_cosmos/src/lib.rs | Wires in the new feed_range module and re-exports FeedRange. |
| sdk/cosmos/azure_data_cosmos/src/hash.rs | Extends internal EffectivePartitionKey capabilities (ordering/hash + conversions) and shares EPK boundary constants. |
| sdk/cosmos/azure_data_cosmos/src/handler/container_connection.rs | Adds accessors for PK definition and routing map resolution (with optional refresh). |
| sdk/cosmos/azure_data_cosmos/src/feed_range.rs | New FeedRange type with serialization/parsing and range relationship helpers + unit tests. |
| sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs | Adds read_feed_ranges + feed_range_from_partition_key APIs using routing map + driver EPK computation. |
| sdk/cosmos/azure_data_cosmos/CHANGELOG.md | Documents the new FeedRange API surface. |
| sdk/cosmos/azure_data_cosmos/Cargo.toml | Adds the base64 dependency for FeedRange string serialization. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/partition_key.rs | Makes PartitionKey::values() public for SDK-side EPK computation. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/partition_key_range.rs | Makes PartitionKeyRange public. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/mod.rs | Exposes effective_partition_key and partition_key_range modules publicly. |
| sdk/cosmos/azure_data_cosmos_driver/src/models/effective_partition_key.rs | Makes driver EffectivePartitionKey public. |
| sdk/cosmos/.cspell.json | Updates spellchecker allowlist for new terminology. |
| Cargo.lock | Locks the added base64 dependency. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…for-rust into port-feed-range
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
analogrelay
requested changes
Apr 13, 2026
simorenoh
commented
Apr 13, 2026
Member
Author
|
/azp run rust - cosmos - weekly |
|
Azure Pipelines successfully started running 1 pipeline(s). |
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
analogrelay
approved these changes
Apr 14, 2026
Member
Author
|
/check-enforcer override |
9eaab0e
into
release/azure_data_cosmos-previews
13 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
FeedRangetype and feed range APIs toazure_data_cosmos, enabling consumers to work with physical partition ranges. It uses the driver's EPK (Effective Partition Key) computation from PR #4087 for correct MultiHash (hierarchical partition key) support, including prefix partition keys.Changes
sdk/cosmos/azure_data_cosmos/src/feed_range.rs(new)New
FeedRangetype representing a contiguous[min, max)EPK range:FeedRange::full()— the complete EPK spacecontains()/overlaps()— containment and overlap checksDisplay/FromStr— base64-encoded JSON serialization (cross-SDK compatible)Serialize/Deserialize— structured JSON for embedding in documentssdk/cosmos/azure_data_cosmos/src/clients/container_client.rsTwo new public methods on
ContainerClient:read_feed_ranges(options)Vec<FeedRange>feed_range_from_partition_key(pk, options)Vec<FeedRange>feed_range_from_partition_keyhandles three cases:DriverEpk::compute()→ point lookup → 1 feed rangeDriverEpk::compute_range()→ overlapping lookup → 1+ feed rangesBoth methods support
ReadFeedRangesOptions::with_force_refresh()to bypass the routing map cache after partition splits.sdk/cosmos/azure_data_cosmos/src/handler/container_connection.rsAdded three accessor methods:
partition_key_definition()— returns the PK definition from the eagerly-resolvedContainerReferenceresolve_routing_map(force_refresh)— resolves the SDK-side routing map with optional cache bypasssdk/cosmos/azure_data_cosmos/src/hash.rsPartialOrd,Ord,Hashderives toEffectivePartitionKey(needed byFeedRange)From<String>andFrom<&str>impls forEffectivePartitionKeyMIN_INCLUSIVE_EFFECTIVE_PARTITION_KEY/MAX_EXCLUSIVE_EFFECTIVE_PARTITION_KEYpub(crate)for reuse infeed_range.rssdk/cosmos/azure_data_cosmos_driver/src/models/(visibility changes)Made the following driver types public so the SDK can use them for EPK computation and routing:
effective_partition_keymodule →pubpartition_key_rangemodule →pubEffectivePartitionKeystruct →pubPartitionKeyRangestruct →pubPartitionKey::values()→pubsdk/cosmos/azure_data_cosmos/src/options/mod.rsAdded
ReadFeedRangesOptionswithwith_force_refresh(bool)for cache bypass control.sdk/cosmos/azure_data_cosmos/tests/emulator_tests/cosmos_feed_ranges.rs(new)5 emulator integration tests:
read_feed_ranges_returns_physical_partitionsfeed_range_from_partition_key_maps_correctlyfeed_range_from_full_hpk_returns_single_rangefeed_range_from_prefix_hpk_returns_rangesfeed_range_from_partition_key_single_hash_full_keyArchitecture Note
The feed range methods use a hybrid approach:
EffectivePartitionKey::compute()/compute_range()(correct MultiHash support from PR #4087)PartitionKeyRangeCache(viaContainerConnection::resolve_routing_map())This is because
CosmosDriverdoes not yet expose aresolve_routing_map()method — the driver'sPartitionKeyRangeCacheexists but isn't wired into the driver struct. Once that infrastructure is added (tracked separately), the feed range methods will switch to the driver's routing map, eliminating the dual-cache situation.