StreamBatchIterator

Struct StreamBatchIterator 

Source
pub struct StreamBatchIterator { /* private fields */ }
Expand description

Iterator for scanning Redis Streams in batches as Arrow RecordBatches.

This iterator fetches stream keys matching a pattern and retrieves their entries, converting them to Arrow RecordBatches for use with Polars. Each entry becomes a row in the output.

Supports two modes:

  1. Single stream: Provide a specific key and iterate through entries
  2. Multi-stream: Provide a pattern to SCAN and fetch entries from each

§Example

use polars_redis::{StreamBatchIterator, StreamSchema, BatchConfig};

let schema = StreamSchema::new(vec![
    ("user_id".to_string(), DataType::Utf8),
    ("action".to_string(), DataType::Utf8),
]).with_key(true).with_entry_id(true);

let config = BatchConfig::new("events:*").with_batch_size(1000);

let mut iterator = StreamBatchIterator::new(url, schema, config)?;

while let Some(batch) = iterator.next_batch()? {
    println!("Got {} entries", batch.num_rows());
}

§Output Schema

  • _key (optional): The Redis stream key
  • _entry_id (optional): The stream entry ID (e.g., “1234567890-0”)
  • _timestamp (optional): Entry timestamp extracted from ID (Int64 ms)
  • User-defined fields from the stream entries

Implementations§

Source§

impl StreamBatchIterator

Source

pub fn new(url: &str, schema: StreamSchema, config: BatchConfig) -> Result<Self>

Create a new StreamBatchIterator.

§Arguments
  • url - Redis connection URL
  • schema - Schema configuration for the stream
  • config - Batch configuration (pattern, batch_size, etc.)
Source

pub fn with_start_id(self, id: &str) -> Self

Set the start ID for XRANGE.

Source

pub fn with_end_id(self, id: &str) -> Self

Set the end ID for XRANGE.

Source

pub fn with_count_per_stream(self, count: usize) -> Self

Set the maximum entries to fetch per stream.

Source

pub fn next_batch(&mut self) -> Result<Option<RecordBatch>>

Get the next batch of data as a RecordBatch.

Source

pub fn is_done(&self) -> bool

Check if iteration is complete.

Source

pub fn rows_yielded(&self) -> usize

Get the number of rows (entries) yielded so far.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V