slbotbm commented on code in PR #3927:
URL: https://github.com/apache/iggy/pull/3927#discussion_r3892814229
##########
foreign/python/apache_iggy.pyi:
##########
@@ -2103,8 +2152,8 @@ class Topic:
r"""
Options admission resolved for the keys the client did not send.
- Same shape as `options`. These would have resolved differently under
- another server configuration.
+ Same shape as [`Self::options`]. These would have resolved differently
Review Comment:
Self::options is a rust term which python users will not understand.
##########
foreign/python/apache_iggy.pyi:
##########
@@ -2168,8 +2217,8 @@ class TopicDetails:
r"""
Options admission resolved for the keys the client did not send.
- Same shape as `options`. These would have resolved differently under
- another server configuration.
+ Same shape as [`Self::options`]. These would have resolved differently
+ under another server configuration.
Review Comment:
same as above -- `Self::options` is a rust term
##########
examples/python/README.md:
##########
@@ -11,7 +11,7 @@ To run any example, first start the server with
docker run --rm -p 8080:8080 -p 3000:3000 -p 8090:8090 apache/iggy:latest
# Or build from source (recommended for development)
-cd ../../ && cargo run --bin iggy-server
+cd ../../ && cargo run --bin iggy-server -- --with-default-root-credentials
Review Comment:
Let's make this `cargo run --bin iggy-server --
--with-default-root-credentials --fresh`
##########
foreign/python/src/partitioning.rs:
##########
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use iggy::prelude::Partitioning as RustPartitioning;
+use pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes};
+use pyo3_stub_gen::{
+ derive::{gen_stub_pyclass, gen_stub_pymethods},
+ impl_stub_type,
+};
+
+/// Defines how a batch of messages is assigned to a topic partition.
+#[derive(Clone)]
+#[pyclass(from_py_object)]
+#[gen_stub_pyclass]
+pub struct Partitioning {
+ pub(crate) inner: RustPartitioning,
+}
+
+#[gen_stub_pymethods]
+#[pymethods]
+impl Partitioning {
+ /// Routes the batch to one partition selected by round-robin.
+ #[staticmethod]
+ pub fn balanced() -> Self {
+ Self {
+ inner: RustPartitioning::balanced(),
+ }
+ }
+
+ /// Routes the batch to the specified partition.
+ ///
+ /// `partition_id` must be between 0 and `2**32 - 1`. The topic must
contain
+ /// that partition when the batch is sent.
+ #[staticmethod]
+ pub fn partition_id(partition_id: u32) -> Self {
+ Self {
+ inner: RustPartitioning::partition_id(partition_id),
+ }
+ }
Review Comment:
`partition_id` accepts a Rust `u32`, so a Python integer outside 0 through
`2**32 - 1` raises `OverflowError` during PyO3 conversion, while a non-integer
raises `TypeError`. The public stub currently only describes the range, unlike
`messages_key` which documents its failures. Add a `Raises` section so the
constructor's contract matches `send_messages()`.
##########
examples/python/basic/producer.py:
##########
@@ -106,7 +106,11 @@ async def produce_messages(client: IggyClient):
await client.send_messages(
stream=STREAM_NAME,
topic=TOPIC_NAME,
- partitioning=PARTITION_ID,
+ # A fixed strategy sends the whole batch to this partition.
+ # For topics with multiple partitions, Partitioning.balanced()
+ # distributes batches round-robin, while
+ # Partitioning.messages_key(key) keeps equal keys on the same
partition.
+ partitioning=Partitioning.partition_id(PARTITION_ID),
Review Comment:
The linked issue explicitly requires a Python message-layer example covering
all three strategies. Either edit the issue, or utilize all three strategies in
the example.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]