Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/cosmos/azure_data_cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features Added

* Added `Query::with_text()` and `Query::append_text()` methods to modify query text after creation ([#3044](https://github.com/Azure/azure-sdk-for-rust/pull/3044))
* Added `PartitionKey::UNDEFINED` constant to represent partition keys for items with no partition key property ([#3075](https://github.com/Azure/azure-sdk-for-rust/pull/3075))

### Breaking Changes

Expand Down
14 changes: 14 additions & 0 deletions sdk/cosmos/azure_data_cosmos/src/partition_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ impl PartitionKey {
/// A single null partition key value, which can be used as the sole partition key or as part of a hierarchical partition key.
pub const NULL: PartitionKeyValue = PartitionKeyValue(InnerPartitionKeyValue::Null);

/// A single undefined partition key value, which identifies the partition containing items with no partition key property at all.
pub const UNDEFINED: PartitionKeyValue = PartitionKeyValue(InnerPartitionKeyValue::Undefined);

/// An empty list of partition key values, which is used to signal a cross-partition query, when querying a container.
pub const EMPTY: PartitionKey = PartitionKey(Vec::new());

Expand Down Expand Up @@ -115,6 +118,7 @@ impl AsHeaders for PartitionKey {
for key in &self.0 {
match key.0 {
InnerPartitionKeyValue::Null => json.push_str("null"),
InnerPartitionKeyValue::Undefined => json.push_str("{}"),
InnerPartitionKeyValue::String(ref string_key) => {
json.push('"');
for char in string_key.chars() {
Expand Down Expand Up @@ -168,6 +172,7 @@ pub struct PartitionKeyValue(InnerPartitionKeyValue);
#[derive(Debug, Clone, PartialEq, Eq)]
enum InnerPartitionKeyValue {
Null,
Undefined,
String(Cow<'static, str>),
Number(serde_json::Number), // serde_json::Number has special integer handling, so we'll use that.
}
Expand Down Expand Up @@ -358,6 +363,11 @@ mod tests {
);
}

#[test]
pub fn undefined_value() {
assert_eq!(key_to_string(PartitionKey::UNDEFINED), r#"[{}]"#);
}

#[test]
pub fn non_ascii_string() {
let key = PartitionKey::from("smile 😀");
Expand All @@ -370,6 +380,10 @@ mod tests {
key_to_string((42u8, "my_partition_key", PartitionKey::NULL)),
r#"[42,"my_partition_key",null]"#
);
assert_eq!(
key_to_string((42u8, "my_partition_key", PartitionKey::UNDEFINED)),
r#"[42,"my_partition_key",{}]"#
);
}

#[test]
Expand Down
Loading