pub trait Record:
Send
+ Sized
+ 'static {
// Required methods
fn schema() -> SchemaRef;
fn to_record_batch(&self) -> RecordBatch;
// Provided methods
fn event_time(&self) -> Option<i64> { ... }
fn to_record_batch_from_iter<I>(records: I) -> RecordBatch
where I: IntoIterator<Item = Self> { ... }
}Expand description
Trait for types that can be streamed through a Source.
Implementations must provide:
- Conversion to/from Arrow
RecordBatch - Schema definition
- Optional event time extraction
§Example
ⓘ
use laminar_core::streaming::Record;
use arrow::array::RecordBatch;
use arrow::datatypes::{Schema, SchemaRef, Field, DataType};
#[derive(Clone)]
struct TradeEvent {
symbol: String,
price: f64,
timestamp: i64,
}
impl Record for TradeEvent {
fn schema() -> SchemaRef {
Arc::new(Schema::new(vec![
Field::new("symbol", DataType::Utf8, false),
Field::new("price", DataType::Float64, false),
Field::new("timestamp", DataType::Int64, false),
]))
}
fn to_record_batch(&self) -> RecordBatch {
// Convert to RecordBatch...
}
fn event_time(&self) -> Option<i64> {
Some(self.timestamp)
}
}Required Methods§
Sourcefn to_record_batch(&self) -> RecordBatch
fn to_record_batch(&self) -> RecordBatch
Converts this record to an Arrow RecordBatch.
The batch will contain a single row with this record’s data.
Provided Methods§
Sourcefn event_time(&self) -> Option<i64>
fn event_time(&self) -> Option<i64>
Returns the event time for this record, if applicable.
Event time is used for watermark generation and window assignment.
Returns None if the record doesn’t have an event time.
Sourcefn to_record_batch_from_iter<I>(records: I) -> RecordBatchwhere
I: IntoIterator<Item = Self>,
fn to_record_batch_from_iter<I>(records: I) -> RecordBatchwhere
I: IntoIterator<Item = Self>,
Converts a batch of records to an Arrow RecordBatch.
The default implementation converts each record individually and concatenates them. Derived implementations can override this to optimize allocation and copying.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.