-
Notifications
You must be signed in to change notification settings - Fork 3k
Fixing gaps for Containers with HashV1 #41222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fixing gaps for Containers with HashV1 #41222
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fills gaps for containers using HashV1 by adding missing V1 hashing utilities and ensuring the version
field is passed when creating PartitionKey
instances.
- Introduce 32-bit MurmurHash3 (
murmurhash3_32
), truncation logic, and V1-specific hashing inPartitionKey
- Propagate the new
version
argument in allPartitionKey
constructor calls across container and client code - Extend
_cosmos_murmurhash3.py
to export the 32-bit hash function
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
sdk/cosmos/.../partition_key.py | Add _truncate_for_v1_hashing , _as_unsigned_long , V1 hash methods, import murmurhash3_32 |
sdk/cosmos/.../container.py | Pass version when instantiating PartitionKey |
sdk/cosmos/.../aio/_cosmos_client_connection_async.py | Pass version in async client PartitionKey creation |
sdk/cosmos/.../aio/_container.py | Pass version when creating PartitionKey in aio |
sdk/cosmos/.../_cosmos_murmurhash3.py | Add murmurhash3_32 implementation |
sdk/cosmos/.../_cosmos_client_connection.py | Pass version and adjust type annotation for pk_properties |
Comments suppressed due to low confidence (2)
sdk/cosmos/azure-cosmos/azure/cosmos/partition_key.py:201
- New V1 hashing methods are introduced but there aren’t corresponding unit tests. Please add tests for
_get_effective_partition_key_for_hash_partitioning
and_truncate_for_v1_hashing
to verify correct behavior.
def _get_effective_partition_key_for_hash_partitioning(
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py:3124
- [nitpick] The variable
pk_properties
is annotated asOptional[PartitionKey]
but it holds a dict of properties. Consider updating the type annotation toDict[str, Any]
or the correct schema type.
pk_properties: Optional[PartitionKey] = kwargs.pop("partitionKeyDefinition", None)
PartitionKey._write_for_hashing(component, ms) | ||
|
||
ms_bytes: bytes = ms.getvalue() | ||
hash_as_int: int = _murmurhash3_32(bytearray(ms_bytes),len(bytes), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to murmurhash3_32
uses len(bytes)
instead of the actual buffer length. Replace len(bytes)
with len(ms_bytes)
to hash the correct number of bytes.
hash_as_int: int = _murmurhash3_32(bytearray(ms_bytes),len(bytes), 0) | |
hash_as_int: int = _murmurhash3_32(bytearray(ms_bytes), len(ms_bytes), 0) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go ahead and change this a bit, we can set the length variable inside _murmurhash3_32 based on the bytearray we passed in similar to the 128 murmurhash.
LGTM, thanks for the quick fix Fabian - will approve once we have tests added for it |
Description
Please add an informative description that covers that changes made by the pull request and link all relevant issues.
If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines