Skip to main content

Record

Trait Record 

Source
pub trait Record:
    Send
    + Sized
    + 'static {
    // Required methods
    fn schema() -> SchemaRef;
    fn to_record_batch(&self) -> RecordBatch;

    // Provided method
    fn event_time(&self) -> Option<i64> { ... }
}
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§

Source

fn schema() -> SchemaRef

Returns the Arrow schema for this record type.

Source

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§

Source

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.

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.

Implementors§