Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FabianMeiswinkel
Copy link
Member

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:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 15:56
@FabianMeiswinkel FabianMeiswinkel requested a review from a team as a code owner May 20, 2025 15:56
Copy link
Contributor

@Copilot Copilot AI left a 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 in PartitionKey
  • Propagate the new version argument in all PartitionKey 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 as Optional[PartitionKey] but it holds a dict of properties. Consider updating the type annotation to Dict[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)
Copy link
Preview

Copilot AI May 20, 2025

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.

Suggested change
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.

Copy link
Member

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.

@simorenoh
Copy link
Member

LGTM, thanks for the quick fix Fabian - will approve once we have tests added for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants