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§
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more