Skip to main content

View

Struct View 

Source
pub struct View<'a> { /* private fields */ }
Expand description

The rows of a view, in its order. Cheap to get; reading never allocates.

A row is a RowRef: which of LiveTable::batches holds it, and where. Read its values from that batch’s columns:

use std::sync::Arc;
use densa_data::arrow_array::cast::AsArray;
use densa_data::arrow_array::{ArrayRef, Float64Array, RecordBatch, StringArray};
use densa_data::{LiveTable, Order, ViewSpec};

let rows = RecordBatch::try_from_iter([
    ("symbol", Arc::new(StringArray::from(vec!["AAA", "BBB"])) as ArrayRef),
    ("price", Arc::new(Float64Array::from(vec![150.0, 90.0])) as ArrayRef),
])?;
let mut table = LiveTable::new(rows.schema(), "symbol")?;
let cheapest = table.add_view(ViewSpec::new().sort_by("price", Order::Ascending))?;
table.upsert(rows)?;

let view = table.view(cheapest).unwrap();
let symbols: Vec<&str> = (0..view.len())
    .filter_map(|i| view.row(i))
    .map(|at| {
        let batch = &table.batches()[at.batch];
        // The column's Arrow type, as the table's schema has it (Utf8 here).
        batch.column_by_name("symbol").unwrap().as_string::<i32>().value(at.row)
    })
    .collect();
assert_eq!(symbols, ["BBB", "AAA"]);

Implementations§

Source§

impl View<'_>

Source

pub fn len(&self) -> usize

Rows in the view.

Source

pub fn is_empty(&self) -> bool

Whether the view is empty.

Source

pub fn row(&self, index: usize) -> Option<RowRef>

Where the row at index (0 is first) is. O(log n).

Source

pub fn record(&self, index: usize) -> Option<RecordId>

The record of the row at index. O(log n).

Source

pub fn position(&self, record: RecordId) -> Option<usize>

Where record’s row is in the view, or None if it is not in it (filtered out, or its key deleted). O(log n): binary searches comparing the row’s sort values.

Trait Implementations§

Source§

impl<'a> Clone for View<'a>

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<'a> Copy for View<'a>

Source§

impl<'a> Debug for View<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for View<'a>

§

impl<'a> !UnwindSafe for View<'a>

§

impl<'a> Freeze for View<'a>

§

impl<'a> Send for View<'a>

§

impl<'a> Sync for View<'a>

§

impl<'a> Unpin for View<'a>

§

impl<'a> UnsafeUnpin for View<'a>

Blanket Implementations§

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.