Skip to main content

Window

Struct Window 

Source
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

Source

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.

Source

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.

Source

pub fn column(&self) -> &str

The time column’s name.

Trait Implementations§

Source§

impl Clone for Window

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Window

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Window

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Window

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.