pub struct Window { /* private fields */ }Expand description
Keeps a LiveTable to its recent rows: those whose value in a time
column is within a span of the newest. Set it with
LiveTable::set_window.
The window ends at the largest finite value of the column among the live rows, so it moves with the data, not with the clock: replayed or delayed data is windowed by its own times, and nothing expires while no rows arrive. A row expires when the end is more than the span past its value; rows whose value is null or NaN never do.
use std::sync::Arc;
use std::time::Duration;
use arrow_array::{ArrayRef, Int64Array, RecordBatch, TimestampMillisecondArray};
use densa_data::{LiveTable, Window};
let ticks = |ids: Vec<i64>, times: Vec<i64>| {
RecordBatch::try_from_iter([
("id", Arc::new(Int64Array::from(ids)) as ArrayRef),
("time", Arc::new(TimestampMillisecondArray::from(times)) as ArrayRef),
])
};
let mut table = LiveTable::new(ticks(vec![], vec![])?.schema(), "id")?;
table.set_window(Some(Window::duration("time", Duration::from_secs(60))))?;
table.upsert(ticks(vec![1, 2], vec![0, 30_000])?)?;
let changes = table.upsert(ticks(vec![3], vec![75_000])?)?;
assert_eq!(changes.deleted, 1); // row 1 is 75 s older than the newest row
assert_eq!(table.len(), 2);Implementations§
Source§impl Window
impl Window
Sourcepub fn duration(column: impl Into<String>, span: Duration) -> Self
pub fn duration(column: impl Into<String>, span: Duration) -> Self
A window of span over a column of timestamps, dates, times of day or durations.
Sourcepub fn span(column: impl Into<String>, span: f64) -> Self
pub fn span(column: impl Into<String>, span: f64) -> Self
A window of span over a column of numbers (integers, decimals or floats), in the
column’s own units: 60_000.0 keeps a minute of milliseconds. span must be zero or
more. A span within a billionth of a whole number of an integer or decimal column’s
units counts as that number, so float error (0.29 hundredths) loses no unit.