DataStream

Struct DataStream 

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

A stream of events with chainable operators

Implementations§

Source§

impl DataStream

Source

pub fn from_events(events: Vec<StreamEvent>) -> Self

Create a new data stream from events

Source

pub fn new() -> Self

Create an empty data stream

Source

pub fn push(&mut self, event: StreamEvent)

Add an event to the stream

Source

pub fn len(&self) -> usize

Get the number of events in the stream

Source

pub fn is_empty(&self) -> bool

Check if stream is empty

Source

pub fn filter<F>(self, predicate: F) -> Self
where F: Fn(&StreamEvent) -> bool,

Filter events based on a predicate

§Example
stream.filter(|e| e.get_numeric("amount").unwrap_or(0.0) > 100.0)
Source

pub fn map<F>(self, mapper: F) -> Self
where F: Fn(StreamEvent) -> StreamEvent,

Transform each event using a mapping function

§Example
stream.map(|mut e| {
    e.add_tag("processed", "true");
    e
})
Source

pub fn flat_map<F>(self, mapper: F) -> Self
where F: Fn(StreamEvent) -> Vec<StreamEvent>,

Transform each event into multiple events (flatMap)

§Example
stream.flat_map(|e| {
    // Split event into multiple events
    vec![e.clone(), e]
})
Source

pub fn key_by<F, K>(self, key_selector: F) -> KeyedStream<K>
where F: Fn(&StreamEvent) -> K, K: Hash + Eq + Clone,

Key events by a specific field or function

§Example
stream.key_by(|e| e.get_string("user_id").unwrap_or("default").to_string())
Source

pub fn window(self, config: WindowConfig) -> WindowedStream

Apply a window to the stream

§Example
stream.window(WindowConfig::sliding(Duration::from_secs(60)))
Source

pub fn reduce<F>(self, reducer: F) -> Option<StreamEvent>

Reduce events to a single result

§Example
stream.reduce(|acc, e| {
    // Accumulate values
    acc
})
Source

pub fn count(self) -> usize

Count the number of events

Source

pub fn collect(self) -> Vec<StreamEvent>

Collect events into a vector

Source

pub fn take(self, n: usize) -> Self

Take only the first n events

Source

pub fn skip(self, n: usize) -> Self

Skip the first n events

Source

pub fn for_each<F>(self, action: F) -> Self
where F: Fn(&StreamEvent),

Process each event with a side effect (doesn’t modify the stream)

§Example
stream.for_each(|e| {
    println!("Processing: {:?}", e);
})
Source

pub fn union(self, other: DataStream) -> Self

Union with another stream

Source

pub fn find<F>(self, predicate: F) -> Option<StreamEvent>
where F: Fn(&StreamEvent) -> bool,

Find events matching a pattern

Source

pub fn any<F>(&self, predicate: F) -> bool
where F: Fn(&StreamEvent) -> bool,

Check if any event matches the predicate

Source

pub fn all<F>(&self, predicate: F) -> bool
where F: Fn(&StreamEvent) -> bool,

Check if all events match the predicate

Source

pub fn sort_by<F, K>(self, key_fn: F) -> Self
where F: Fn(&StreamEvent) -> K, K: Ord,

Sort events by a key function

Source

pub fn group_by<F, K>(self, key_selector: F) -> GroupedStream<K>
where F: Fn(&StreamEvent) -> K, K: Hash + Eq + Clone,

Group events by a key and apply aggregation

Source

pub fn aggregate<A>(self, aggregator: A) -> AggregateResult
where A: Aggregation,

Apply an aggregation function

Trait Implementations§

Source§

impl Clone for DataStream

Source§

fn clone(&self) -> DataStream

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for DataStream

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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

Source§

impl<T> ErasedDestructor for T
where T: 'static,