Skip to main content

laminar_core/operator/
mod.rs

1//! Streaming operator types and window assigners for stream processing.
2
3use std::sync::Arc;
4
5use arrow_array::RecordBatch;
6use smallvec::SmallVec;
7
8/// Timer key type optimized for window IDs (16 bytes).
9pub type TimerKey = SmallVec<[u8; 16]>;
10
11/// An event flowing through the system.
12#[derive(Debug, Clone)]
13pub struct Event {
14    /// Timestamp of the event
15    pub timestamp: i64,
16    /// Event payload as Arrow `RecordBatch` wrapped in `Arc` for zero-copy multicast.
17    pub data: Arc<RecordBatch>,
18}
19
20impl Event {
21    /// Create a new event, wrapping the batch in `Arc` for zero-copy sharing.
22    #[must_use]
23    pub fn new(timestamp: i64, data: RecordBatch) -> Self {
24        Self {
25            timestamp,
26            data: Arc::new(data),
27        }
28    }
29}
30
31/// Errors that can occur in operators.
32#[derive(Debug, thiserror::Error)]
33pub enum OperatorError {
34    /// State access error
35    #[error("State access failed: {0}")]
36    StateAccessFailed(String),
37
38    /// Serialization error
39    #[error("Serialization failed: {0}")]
40    SerializationFailed(String),
41
42    /// Processing error
43    #[error("Processing failed: {0}")]
44    ProcessingFailed(String),
45
46    /// Configuration error (e.g., missing required builder field)
47    #[error("Configuration error: {0}")]
48    ConfigError(String),
49}
50
51impl From<arrow_schema::ArrowError> for OperatorError {
52    fn from(e: arrow_schema::ArrowError) -> Self {
53        Self::SerializationFailed(e.to_string())
54    }
55}
56
57pub mod sliding_window;
58pub mod window;
59
60#[cfg(test)]
61mod tests;