-
Notifications
You must be signed in to change notification settings - Fork 934
Expose deterministic partitioner functions in Python #2116
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: master
Are you sure you want to change the base?
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
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 exposes three deterministic partitioner functions from librdkafka to allow users to manually calculate partition IDs for validation purposes, eliminating the need for platform-dependent ctypes calls.
- Added C extension wrappers for murmur2, consistent, and fnv1a partitioner functions
- Exposed functions through Python API with proper type hints and documentation
- Added comprehensive tests covering correctness, deterministic behavior, and input validation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_partitioners.py | Added unit tests for the three partitioner functions |
| src/confluent_kafka/src/confluent_kafka.c | Implemented C extension wrappers with shared helper function |
| src/confluent_kafka/cimpl.pyi | Added type hints for the new partitioner functions |
| src/confluent_kafka/init.py | Exported the new functions to the public API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| " Calculate partition using Murmur2 hash (Java-compatible).\n" | ||
| "\n" | ||
| " Deterministic function using Murmur2 hashing algorithm.\n" | ||
| " assigned to.\n" |
Copilot
AI
Oct 30, 2025
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.
This line appears to be a documentation fragment that doesn't make sense in context. It should be removed or completed with proper context.
| " assigned to.\n" |
3c42321 to
d54374d
Compare
|




What
Why
Users need to manually calculate partition IDs for validation purposes (e.g., verifying messages are delivered to the correct partition). Currently, they must use ctypes to directly call librdkafka functions, which is platform-dependent and not officially supported.
What
Exposes three deterministic partitioner functions from librdkafka:
murmur2(key: bytes, partition_count: int) -> int- Java-compatible Murmur2 hashconsistent(key: bytes, partition_count: int) -> int- CRC32-based hashfnv1a(key: bytes, partition_count: int) -> int- FNV-1a hashChanges
cimpl.pyi__init__.pyfor public APIUsage
Checklist
References
JIRA: https://confluentinc.atlassian.net/browse/NONJAVACLI-4098
Issue: #1759
Test & Review
Open questions / Follow-ups